
please wait
|
|
isValid = strncmp(str1, str2, MAX(strlen(str1), strlen(str2));
ciphermagi (793) Look again at my post. There should have been 9 steps, because the string passed to srtlen was "exit toll", not "exit". That's not even complete code, because I would actually define it more like this: #define MAX(x, y) ((x) >= (y) ? (x) : (y)) .. .. .. isValid = strncmp(str1, str2, MAX(strlen(str1), strlen(str2)); |
That's not the point, Disch. |
@ciphermagi |
That's not the point, Disch. With this code you have a buffer defined. You don't buffer overrun because the program actually handles the whole thing. Since your strings can't exceed the buffer, no, the trick doesn't work, because you can't cause undefined behavior in the program. |
strlen isn't subject to those attacks because of two factors, and only the fact that these are both present make it immune to the same attack: One is that there is only one string involved, and the other is that the function terminates at '\0', which is the end of the buffer. |
Disch, part of the point I was making is that since you force a buffer definition, even though it's an awkward one, you're preventing the buffer overrun attacks. |