News for hackers. Stuff that matters.
Re:C Strings and my slow descent to madness by myrmidon on Thursday April 06, 2023 @09:27PM (#35476922)
Are you sure that strncpy does an out-of-bound write here? I believe it doesnt, but would give you an unterminated string in buf which is also... less than ideal (if the input is 80 non-null characters or longer).
Re:C Strings and my slow descent to madness by nneonneo on Thursday April 06, 2023 @09:30PM (#35476951)
Ugh, I had that in my comment before I "refactored" it. Fixed now, thanks for pointing it out.
Re:C Strings and my slow descent to madness by Lt_Riza_Hawkeye on Thursday April 06, 2023 @11:40PM (#35477769)
Yeah, and I wouldn't say it's definitely unsafe. You can memchr a '\0' out of it (or not) to determine if a null terminator got in there or not.
Re:C Strings and my slow descent to madness by nneonneo on Friday April 07, 2023 @01:03AM (#35478216)
I mean, you could but a lot of people do not. Plus, strncpy is terribly inefficient if the source string is tiny, because it’ll fill the rest of the buffer with NULs.
Re:C Strings and my slow descent to madness by myrmidon on Friday April 07, 2023 @03:09PM (#35485713)
One mans inefficiency is another mans resistance to timing attacks :P

(this is tongue-in-cheek, the function is still bad IMO because it almost never does what you need it to. If it guaranteed null termination it would be more useful)