Implementing a web server in a single printf() call (2014)
(tinyhack.com)64 points by nateb2022 4 days ago
64 points by nateb2022 4 days ago
It is the only one that actually writes to memory. It's occasionally convenient, but it's also largely unnecessary: the caller can typically make multiple calls to printf, for example, noting the return value for each one. Or use strlen and fputs. And so on.
The C11 printf_s functions don't support it at all, so it's clearly already on the naughty list even from the standard's perspective.
As soon as you forget (or your adversary manages to delete) an \0 at the end of any string, you may induce buffer overflows, get the application to leak secrets, and so on. Several standard library functions related to strings are prone to timing attacks, or have weird semantics that may expose you to attack. If you roll your own security-related functions (typical example: a scrubber for strings that hold secrets), you need to make sure these do not get optimised away by the compiler.
There's an awful lot of pitfalls and footguns in there.
Discussion at the time (181 points, 39 comments) https://news.ycombinator.com/item?id=7389623
OpenBSD has removed the format specifier that makes this possible, for hopefully obvious reasons.