A curated set of progressively challenging C exercises focused on security, systems programming, and embedded development. From low-level memory safety to real-time device drivers, each task is designed to build practical skills for real-world applications.
Feel free to pull-request any changes, from codes to this README
! And if you find these challenges useful please share it with your friends and star! ⭐
- Minimal Hex Dumper: Print a file in hex, with offset addresses and ASCII alongside.
- Command-line Parser: Read arguments with
getopt
(or manually), handling short/long switches. - Safe Reader: Replace
gets
/scanf("%s")
with a loopedread
that enforces buffer limits. - Accurate Timer: Measure the runtime of a function using
clock_gettime
(ns precision). - Single-file CRC32: Compute CRC32 for an input file and check against a reference value.
- Lightweight INI Parser: Convert a
.ini
file into a key=value map. - Rotating Log: A log file that rotates after reaching X KB (rename + new file).
- Rate Limiter: Sliding window to limit requests on stdin.
- Safe Tempfiles: Create temporary files with
mkstemp
and clean them up via signals. - Bitfield Practice: 32-bit register struct with bitfields; set/clear/test bits.
- Endian Swap: Implement
bswap16/32/64
and detect system endianness. - ASCII Armor: Base64 encode/decode binary input (streaming).
- Normalize Path: Remove
.
/..
and multiple slashes without callingrealpath
. - Memory Zeroize: A function that won’t be optimized away by the compiler (
volatile
/memset_s
fallback). - Small Arena Allocator: Linear arena with a global reset.
- Bounded Str API: Implement safe versions of
strlcpy/strlcat
. - FNV-1a Hash: 32/64-bit hash for strings; implement a small hash table.
- Mini-printf: Implement limited
%s %d %x
without heavy dependencies. - Signal-safe Logger: Print critical messages only using signal-safe syscalls.
- Userland Watchdog: Kill and restart a child process if it hangs.
- Cat with
mmap
: Copy large files usingmmap
(zero-copy). - Safe Dir Walker: Traverse directories with
fdopendir
and prevent TOCTOU attacks. - Atomic File Copy: Write to a temp file,
fsync
, thenrename
atomically. - Limited Shell: Safely execute a few whitelisted commands using
posix_spawn
. - Resource Limits: Sandbox a process with
setrlimit
(CPU/mem/FD limits). - Syslog Client: Send logs to syslog with a local file fallback.
- Lock File: Process-level lock using
flock
+ stale lock detection. - Epoll Echo: Echo server with
epoll
/non-blocking I/O and fixed buffers. - Timeout Read/Write: I/O with
poll
and connection drop handling. - Unix Domain Socket: Local messaging with sender UID validation.
- Pipe Chain: Implement
cmd1 | cmd2 | cmd3
withpipe
/dup2
. - Signal Supervisor: Handle SIGINT/SIGTERM with clean shutdown.
- Config Hot-Reload: Receive SIGHUP and reload config without downtime.
- Replay-safe Journal: Journal file with checksum for crash recovery.
- RLE Compression: Simple run-length encoding for data streams.
- TTY Raw Mode: Read keys without echo, implement a mini-REPL.
- Secure Random: Seed from
/dev/urandom
with health checks. - Timer Callback: Implement a timer wheel for event expiry.
- Atomic Config Loader: Double-buffered config struct with simple RCU.
- Benchmark Framework: Lightweight micro-benchmarking module.
- Safe Unpacker: Unzip a simple zip file with size/count/path traversal limits.
- chroot Sandbox: Run a tool inside a chroot and drop privileges.
- Stack Canary Demo: Implement and check a software canary around buffers.
- Seeded Fuzzer: Dumb fuzzer for a simple line parser, with corpus and crash saving.
- TLS Fingerprint (JA3-lite): Extract TLS client features from pcap (header parse only).
- ELF Header Reader: Display
e_type/e_machine/entry
and section info. - Symbol Resolver: Read ELF symbol table and search for functions.
- Procfs Inspector: Get a process’s memory map from
/proc/<pid>/maps
. - LD_PRELOAD Hook: Educational hook counting calls to
open
. - Syscall Filter (seccomp-bpf): Block unneeded syscalls for a simple tool.
- Address Sanitizer-lite: Maintain guard zones for malloc/free in custom allocator.
- Minimal Race Detector: Force locking and detect simple concurrency races.
- Password KDF: PBKDF2 or scrypt wrapper around a standard library.
- HMAC-SHA256 Wrapper: API with key in locked memory (
mlock
). - Replay Protection: Persistent nonce counter with checksum.
- Simple Taint Tracking: Flag “untrusted” data throughout a pipeline.
- JWT Verifier (HS256): Verify signature and exp/nbf only, no risky decoding.
- Zip Bomb Guard: Limit compression ratio and abort if exceeded.
- Format-String Guard: Safe wrapper for printing unknown strings.
- Secure Wipe File: Multi-pass overwrite +
fsync
+ rename + unlink.
- Thread Pool: Job queue with N workers, clean shutdown.
- Lock-free Ring Buffer: Single-producer/single-consumer with
atomic
. - Shared Memory IPC: Message queue with
shm_open
+pthread_cond
in shared memory. - kqueue/epoll Abstraction: Cross-platform event layer (Linux/BSD).
- Zero-Copy Sendfile: Static web server using
sendfile
and ETag. - Syslog Server: UDP syslog receiver writing to disk in batches.
- Netlink Listener: Monitor network events (link up/down).
- Small DNS Resolver: A/AAAA queries over UDP, with timeout/backoff.
- HTTP/1.1 Parser: State machine resilient to packet splitting/merging.
- Token Bucket Rate Limiter: General-purpose limiter for sockets.
- Process Supervisor: Restart on crash with exponential backoff and max tries.
- cgroup v2 Sandbox: Limit CPU/mem/IO for a child process.
- Perf Counter Hook: Measure cache misses with
perf_event_open
. - NUMA-aware Alloc: Bind threads and allocate memory on a specific node.
- File Integrity (FS-verity-lite): Merkle tree for large files.
- Crash Dump Writer: Catch signals and write a mini dump of registers.
- Pluggable Modules: Dynamically load
.so
files with a fixed interface. - Trie/IP CIDR Match: CIDR routing/firewall with longest-prefix matching.
- Bloom Filter: Memory-efficient filter with false positive evaluation.
- PCAP Writer: Save raw packets in pcap format.
- ISR-safe Ring Buffer: Circular buffer for UART RX in ISR + consumption in main loop.
- Button Debounce: Anti-bounce logic for buttons using timer/state machine.
- GPIO Driver: Implement
gpio_set/clear/toggle
with memory-mapped registers. - PWM LED Control: Soft fading with hardware timer.
- I²C Master: Read temperature from a sensor (e.g., LM75) using a state machine.
- SPI Flash Reader: Read JEDEC ID and blocks with checksum.
- Minimal UART Bootloader: Receive frames, verify length+CRC, write to flash (simulated).
- RTOS Tasks: Two tasks with a message queue; priority and starvation tests.
- Fixed-point Math: Moving average filter on ADC values with Q15.
- Hardware Watchdog: Feed WDT and test reset.
- Low-power Mode: Deep sleep and wake-up on timer interrupt.
- Motor State Machine: Four states with safe error transitions.
- CRC peripheral vs software: Compare performance on board.
- Boot-time Self-test: Test RAM/Flash/Clock and report errors via LED code.
- Circular DMA: Continuous ADC sampling with circular DMA and half/full interrupts.
- Cooperative Scheduler: Task scheduler without interrupts, round-robin.
- Flash Wear Leveling: Key=value store layer with wear leveling.
- Very Simple Filesystem: Log-structured FS on simulated flash.
- Embedded Cryptobox: AES-GCM using a lightweight library, key in locked memory, correct nonce.
- Over-the-Air Update Simulation: Receive packages, verify signature, switch boot slot.