reposting for the day crowd: I ran into a memcmp implementation that only compared 25% of the bytes, and the issue wasn't caught in the build because the vendor toolchain failed to emit a warning.
reposting for the day crowd: I ran into a memcmp implementation that only compared 25% of the bytes, and the issue wasn't caught in the build because the vendor toolchain failed to emit a warning.
@gsuberland Hmm, would even fuzz testing find it? That seems tricky to set up in a way that a) would actually find the bug and b) would occur to you before seeing the bug.
I guess for very short inputs you might find it more easily by chance...
@gsuberland oh yeah i saw this earlier and thought surely the compiler would yell at you for that comparison
oopsie
@uecker I might've bungled the flags in the post, 'cos I was tired, but the actual flags they were using in the build did generate the warning in gcc.
I would expect -Wnarrowing to catch implicit narrowing conversions, though.
@gsuberland Oh my, that's horrible!
Btw what do you mean by "constant-time"? It seems that the function would take time linear in "words" parameter.
@lisyarus for example if I did:
if (strcmp(password, "hunter2") == 0) { ... }
strcmp has an early-out optimisation where the comparison loop exits at the first mismatched character. by iterating each character sequentially while timing how long the comparison takes I can discover which character causes the comparison time to increase slightly, which lets me discover the password letter by letter.