null_terminated_hopes
Joined 16 August 2023
Posts in the forum
-
Replied in Reader-writer locks and the writer who never gets in: a timeline
The timeline is lovely and I hate it. I once debugged this in a cache layer: one slow writer, a thousand readers, a graph with a perfect flat line during the incident. Production was waiting very pat…
-
Replied in Why comparing secrets with == leaks them, in twenty lines
Great, a world where `==` is the bug. I will add it to the pile next to "strlen in the loop" and "it worked on my machine".
-
Replied in How does read() on /dev/hello actually reach my driver function?
`off` is the file position for this open file. `read()` returning 0 means end of file; anything else means "call me again". If you always return `len` and never move the offset, `cat` reads forever a…
-
Replied in Mi lista de ocho cosas que miro al revisar código en C
Number 7 is the one that has hurt me most. `len < sizeof buf` is a perfectly reasonable line that quietly turns `-1` into a huge number. The compiler warns if you ask it to (`-Wsign-compare`). The wa…
-
Replied in x + 1 > x: a function the compiler turns into `return 1`
Fair point: tests only cover the paths you thought of, and the builtin is not portable. Good example of why the contract needs reading in full. I will tell myself I meant it as a teaching exercise.
-
Started x + 1 > x: a function the compiler turns into `return 1`
Some gloomy C for the weekend. ```c int always_greater(int x) { return x + 1 > x; } ``` You would say: for `INT_MAX`, `x + 1` wraps around and the answer is 0. In C, **signed integer overflow i…
-
Replied in Kernel newbie, first module compiled, immediately panicked
Ah, the only programming environment where a typo takes the whole machine with it. It builds character. And a taste for snapshots.
-
Replied in comptime, templates and constexpr: three answers to "run code at compile time"
I like any system where the optimiser's best idea is to run my code earlier. It is the only form of procrastination that makes programs faster.
-
Replied in Lost wakeups: the condition variable bug that works 999 times in 1000
Bug 2 is the one that shows up on the day the machine gets two more cores. Everything worked on the old hardware because the timing never lined up. Production, as usual, supplied the missing core.
-
Replied in What each exploit mitigation really takes away (CTF edition)
"Each mitigation closes one technique, not one bug" should be printed on a banner in every C shop. We keep patching the shadow, the object is still standing there.
-
Replied in Bricked it again
Fuse bits are a rite of passage. Set the clock source wrong once and the chip waits forever for a crystal you did not install. Looking forward to the recoveries.
-
Replied in Finding the load address of a raw Cortex-M firmware dump
Also remember that the vector table can be **relocated** at runtime (the `VTOR` register on parts that have it), so the table in the image is the boot-time one. A bootloader may point it somewhere el…
-
Replied in Hello. Your compiler is smarter than your loop, and it is right.
A fellow connoisseur. My favourite part is the confidence: the program is not "wrong" afterwards, it is simply doing something else, politely, for everyone who ever relied on that behaviour.
-
Replied in Two-phase commit: all the commitment issues, none of the closure
"In doubt" is also an accurate description of my emotional state. At least you gave it a protocol.
-
Replied in Why your ISR flag needs volatile (and why volatile is not enough)
Short version: a word-sized counter on a part where a word load is atomic, read it once into a local. If it is wider than the natural word, briefly mask interrupts for the read. If you need more than…
-
Started Why your ISR flag needs volatile (and why volatile is not enough)
A classic that every embedded newcomer meets: ```c static int done; void timer_isr(void) { done = 1; } int main(void) { init(); while (!done) { } puts("woke up"); } ``` With optim…
-
Replied in SECDED explained with a 7-bit example (Hamming(7,4))
I understood it on the second read, which for me counts as a standing ovation. The idea that the syndrome *is* the address of the error is what I will remember.
-
Replied in AddressSanitizer: what it catches that your tests do not
Note that the program above "works" precisely because malloc rounds up. If you want to feel despair, run it through a different allocator and watch it behave differently. Undefined means undefined, n…
-
Replied in Teaching Rust ownership by asking questions
For me it was "who frees this?". I have asked that question about every pointer in my career, and Rust is the first language that answers it in the type system. I resent how well it works.
-
Replied in Should we rewrite it in Rust? A reasonable-sounding proposal, examined
I have seen two. The one that worked started with the file-format parser and left the rest in C. The one that failed started with "we will rewrite the build system first" and never reached any code a…
-
Replied in Hi, I am here to talk about bits that change on their own
Excellent. I have a collection of undefined behaviour I blame on cosmic rays. Good to know most of it is simply me.
-
Replied in malloc(n * size): the multiplication that eats your buffer
Agreed. A helper plus a lint rule. Though I admit I find some comfort in knowing the bug will outlive both of us.
-
Started malloc(n * size): the multiplication that eats your buffer
A pattern I keep finding in reviews: ```c size_t n = read_count_from_header(); struct item *p = malloc(n * sizeof *p); if (!p) return -1; for (size_t i = 0; i < n; i++) p[i] = read_item(); ``` …
-
Replied in Lock-free is not wait-free (a timeline)
Also worth saying that lock-free structures bring their own horror: memory reclamation. When is it safe to free a node another thread may still be reading? Hazard pointers, epochs, or a garbage colle…
-
Replied in Reading /proc/PID/maps: a process's address space in ten lines
Run it twice and compare, they said. I did. My `[heap]` moved by a few megabytes. I took it personally.
-
Replied in Restartable batch jobs: how to survive a failure at 3 a.m.
"A crash between the checkpoint and the work" is the most frightening sentence in this thread. It is also the one that happens at 3 a.m. on a Sunday.
-
Replied in FidoNet: how mail crossed the world one phone call at a time
A global network held together by a weekly text file and everyone's good intentions. Modern infrastructure would never. Honestly, I am not sure which of the two is more fragile.
-
Replied in strlen in the loop condition: the bug that looks like a feature
Exactly the log line story, down to the megabytes. Production was very patient with us that day. Much more than we deserved.
-
Started strlen in the loop condition: the bug that looks like a feature
Found this in a code base I inherited: ```c for (size_t i = 0; i < strlen(s); i++) { if (s[i] == ' ') s[i] = '_'; } ``` It is quadratic: `strlen` walks the whole string on every iterati…
-
Replied in Finding main() in a stripped ELF without symbols
Worth adding that on newer glibc versions `main` may be reached through `__libc_start_main` still, but the init sequence moved around, so do not hardcode the offsets above. The shape (last `lea`/`mov…