Re:A Regular Expression Matcher (2007)
by groovy2shoes on Monday August 01, 2016 @05:50AM
(#12201175)
> strncat() is not like strncpy() - it always nul-terminates the result.
Yes, you're right. That's what I get for trying to speed-read the C standard at 3am...
> I think your strlen() issue is a bit overblown. Either you get the string from a function that explicitly produces valid strings, in which case you know that it's a valid string already; or you get it from a raw bunch of bytes which tends to come with a size attached, giving you all the information you need to either check if it's a valid string or append a nul-terminator yourself.
Usually, yes, but neither of those things are guaranteed, unfortunately, and thus we wind up with the perennial buffer overflow exploit.
Yes, you're right. That's what I get for trying to speed-read the C standard at 3am...
> I think your strlen() issue is a bit overblown. Either you get the string from a function that explicitly produces valid strings, in which case you know that it's a valid string already; or you get it from a raw bunch of bytes which tends to come with a size attached, giving you all the information you need to either check if it's a valid string or append a nul-terminator yourself.
Usually, yes, but neither of those things are guaranteed, unfortunately, and thus we wind up with the perennial buffer overflow exploit.