Re:Making C Less Dangerous in the Linux Kernel [video]
by greesil on Sunday January 27, 2019 @12:44AM
(#19010504)
I didn't even know that scnprintf was a thing. Cool! I learned something just by skimming the video
[ Parent
| on HN ]
Re:Making C Less Dangerous in the Linux Kernel [video]
by ddtaylor on Sunday January 27, 2019 @12:47AM
(#19010512)
I think the presenter mentions it's only in Linux kernel though, not available in userspace.
Re:Making C Less Dangerous in the Linux Kernel [video]
by chacham15 on Sunday January 27, 2019 @12:53AM
(#19010523)
The userspace version is snprintf.
Re:Making C Less Dangerous in the Linux Kernel [video]
by technion on Sunday January 27, 2019 @02:56AM
(#19010805)
There's a great write up here on how assuming scnprintf behaved like snprintf led to memory bugs:
http://blog.infosectcbr.com.au/2018/11/memory-bugs-in-multip...
Re:Making C Less Dangerous in the Linux Kernel [video]
by aboutruby on Sunday January 27, 2019 @12:58AM
(#19010533)
The speaker mentions it, seems like the return value is different: https://i.imgur.com/Jj2fMZu.png
Re:Making C Less Dangerous in the Linux Kernel [video]
by Taniwha on Sunday January 27, 2019 @06:10PM
(#19014343)
yes - snprintf() returns the length of the string that would be written even if it wasn't clipped to the length of the output buffer - if you want to accumulate strings into a buffer using the output length to update the offset/size bad things will happen.
scnprintf() returns the actual number of bytes written (less the null)