News for hackers. Stuff that matters.
Re:Considering C99 for Curl by unwind on Tuesday November 22, 2022 @03:04PM (#33710656)
If anyone reading this and feels uncertain on how this is done, DON'T do this:

    snprintf(dest, sizeof dest, source);   // BAD code do not repeat
that looks great at first sight, just another size-checked way of copying strings, but remember that the third argument to `snprintf()` [1] is of course a `printf()`-style formatting string. So if that `source` argument contains any percent symbols, there's gonna be a party in your computer and both Undefined and Behavior are going to show up. You don't want that.

Instead, if you want to use `snprintf()` for this, remember to do:

    snprintf(dest, sizeof dest, "%s", source);

[1]: https://linux.die.net/man/3/snprintf
Re:Considering C99 for Curl by Karellen on Tuesday November 22, 2022 @03:44PM (#33711248)
Thanks for mentioning this. I didn't include it in my comment because I originally thought it was too obvious, but considering it now, it probably was worth making explicit.
Re:Considering C99 for Curl by unwind on Tuesday November 22, 2022 @04:07PM (#33711521)
I blame Stack Overflow for conditioning me into seeing more of the possible ways things could break, when it comes to C code. :)
Re:Considering C99 for Curl by jbboehr on Tuesday November 22, 2022 @11:34PM (#33715216)
`-Wformat-security` [0] to the rescue!

[0]: https://fedoraproject.org/wiki/Format-Security-FAQ