by ars · 11y ago · 0 comments
Sample buggy code (that I just made up):
(user_token is user supplied token, token is the correct token)
for(i = 0; i < strlen(user_token); i++) {
if(user_token[i] != token[i]) return false;
}
return true;
If code is blank this will falsely return true. This is also subject to truncation attacks.I'm trying to think of a bug where blank fails, but truncated versions do not.
if(!check_params()) {
failed = true;
goto fail;
}
if(some_other_check()) {
failed = true;
goto fail;
}
if(token_length == 0) {
goto fail; // oops, forgot to set failed
}
...check the token...
fail:
if(failed) {
return auth_failure;
}
I have no idea if this is anything like what actually happened, of course.But I guess you're right, better safe than sorry.
strcmp() is at least better than a buggy equivalent that doesn’t actually work :)
If this is in fact how how things worked, what a great showstopper bug