Re:strcpy: A niche function you don't need
by guidovranken on Friday July 30, 2021 @06:43PM
(#28013329)
snprintf works most of the time but it can fail, and people almost never check the return value. For example it will always fail if you attempt to print a string >= 2GB. If that happens the output buffer may remain uninitialized (depends on the implementation) and you're at risk for a Heartbleed-like scenario.
[ Parent
| on HN ]
I'm curious, what type of application would require printing strings over 2GB in size?
Re:strcpy: A niche function you don't need
by guidovranken on Friday July 30, 2021 @08:42PM
(#28014125)
(Intentionally crafted) large metadata in a video file (which can be very large anyway, so 2GB extra doesn't stand out). A string field in a (machine-generated) JSON/XML dataset. And like tomohawk says, lack of a mechanism that prevents accruing large blobs (for example not limiting the size of an incoming HTTP header in a web server).
Re:strcpy: A niche function you don't need
by staticassertion on Friday July 30, 2021 @11:38PM
(#28015059)
The one that plans to print much shorter strings, but accepts arbitrary strings.
Re:strcpy: A niche function you don't need
by tsimionescu on Saturday July 31, 2021 @02:56AM
(#28015981)
Binary file contents are often strings, right? If you're using snprintf() to copy strings, as the thread was suggesting, there are valid reasons to try to copy such strings (though they would be few and far between).