Programming Foundations
Programs turn input into behavior, but the path between the two matters. A value might be converted before a comparison, skipped by a loop, or passed into a function that expects something different. To understand the result, you have to follow what the program actually did with that value.
Later in the vulnerability research series, we’ll ask whether a program’s assumptions can fail in ways that matter for security. This module gives us the programming knowledge to understand those assumptions first. You don’t need to become a professional software developer before starting. We’ll read small programs, predict their behavior, and change one thing at a time until we can explain the result.
We’ll start with Python, because it lets us concentrate on program behavior without dragging in a compiler and manual memory management at the same time. Then we’ll move to C, where we’ll work directly with compiled instructions and memory layouts. C is considerably less forgiving, which is inconvenient when you’re writing software and genuinely educational when you’re researching it.
Prerequisites
Section titled “Prerequisites”Finish Linux Foundations before you start here. You should be comfortable navigating with paths, creating and inspecting text files, redirecting output, identifying an exit status, and reading a manual page. This module assumes those habits and no prior Python or C experience at all.
If paths, permissions, or shell quoting still feel unpredictable, go back to the matching Linux lesson first (adding programming syntax on top of an unsteady shell just hands you two problems at once).
Module sequence
Section titled “Module sequence”Learning how programs behave
Section titled “Learning how programs behave”- What Is a Program? Source code, instructions, input, output, state, and what running code actually means.
- Python Scripts and Values. Your first scripts, variables, basic types, and terminal arguments.
- Decisions and Repetition. Conditions, comparisons, loops, and tracing the path a program takes.
- Functions, Errors, and Files. Breaking work into functions, reading failures, and pulling data off disk.
- Python Behavior Lab. Investigate a script whose behavior changes with its input.
Getting closer to the machine
Section titled “Getting closer to the machine”- C Programs and Compilation. Start C from its own beginning: read a small program line by line, build and change it, then connect source, objects, and the executable.
- Types, Functions, and Control Flow in C. Revisit familiar programming ideas under C’s much stricter rules.
- Arrays, Strings, Pointers, and Memory. Connect C values and bounds to the bytes a program is allowed to touch.
- C Memory Lab. Predict and then observe how a small program lays out and changes its data.
Putting the process together
Section titled “Putting the process together”- Reading Unfamiliar Code. Turn source into a map of inputs, decisions, state changes, and outputs.
- Code Investigation Lab. Put the whole process to work on an unfamiliar but bounded program.
Tools used in this module
Section titled “Tools used in this module”Everything runs inside the Linux course VM, and we’ll be using:
- the terminal and filesystem commands from Linux Foundations
- a plain text editor
- Python 3
- GCC, the GNU C compiler
- the ordinary command-line inspection tools
- small course programs that are safe to change and break
Setup instructions turn up the first time each tool is needed, so install things when you’re prompted rather than in advance. A missing dependency is a lot easier to spot that way.
Knowing how a Python function behaves doesn’t mean you already know how to write one in C. We’ll keep the useful ideas, but explain C’s notation and build workflow from the beginning. You shouldn’t have to guess what a brace or declaration means just because it’s the second language in the course.
How to work through the examples
Section titled “How to work through the examples”Keep one directory for your programming exercises. Try the examples and compare their output with what you expected. Notes are optional; a scratch trace can help when a value passes through several steps.
That prediction step probably feels slow at first, and it’s also where debugging and careful investigation begin. Running a program over and over with no question in mind isn’t investigation, it’s just making the computer warm.
Start with What Is a Program?, which sets up the vocabulary the rest of the module leans on.