2 ms·
You can do silly things with the format string, but it will never overflow the output buffer if you invoke snprintf properly, nor will it ever not be null termi
by TazeTSchnitzel 6y ago
You can do silly things with the format string, but it will never overflow the output buffer if you invoke snprintf properly, nor will it ever not be null terminated, and snprintf can even tell you how large a buffer you need.
- hnick 6y agoOh yea, I was just thinking there are still limits to what 'safe' means though. My memory on the exact exploits was hazy so I had to look it up but I know it includes sending user defined data to the format string, which is not advised, but people do silly things all the time when coding which is why snprintf exists to start with. People can't be trusted to bounds check. In my mind a safer version for daily use wouldn't support the more problematic format options but maybe other people use them far more widely than me.
- TazeTSchnitzel 6y agoRight, yeah, I should say snprintf() is safer than sprintf(), but it still has the unsafe features of printf().