specifically check the function SSLVerifySignedServerKeyExchange
I leave the joy of spotting it to you. It is obvious and if you know c you'll see it(You don't need any knowledge of crypto).
specifically check the function SSLVerifySignedServerKeyExchange
I leave the joy of spotting it to you. It is obvious and if you know c you'll see it(You don't need any knowledge of crypto).
Check line 631. Appears seemingly out of nowhere.
But, are you sure the 10.8.5 (-55179.13) version isn't in some sense a later, patched maintenance branch compared to a 10.9 (-55471) that might have been frozen earlier? The release dates are very close (~2013-10-03 for 10.8.5; ~2013-10-22 for 10.9), and they might have already been separate branches.
(Is there a 10.8.4 version to compare?)
It doesn't seem like what you said is the case here but obviously we're still missing changesets that may have been committed between 10.8.5 (Security-55179.13) and 10.9 (Security-55471). It'd be really interesting to do a git-blame on that file.
EDIT: Nevermind, that file wasn't open-sourced in 10.8. It's actually really old. (Look for directories starting with libsecurity_ssl in pre-10.8 OS X versions.) Didn't find anything particularly interesting in the old versions though.
Others might say it's a problem of whitespace insensitive languages ;)
It might be more noticeable, but then, the original bug existed because no one noticed.
Execution will arrive there somehow, but the 'how' is unclear. The word "fail" implies you should reach that point only if there was an error, but that is a bad assumption in this case.
If the real answer to 'how did we get here?' was checked, then the bug could not hide in the undefined behavior. This would not allow a dangling goto to result in a false positive. A false negative will get someone's attention when their web page doesn't load.
Something like this could remove the undefined state:
goto pass;
fail:
if ( err == 0 ) {
assert( err != 0 ); // BUG! variable must contain an error number
err = kSomeAppropriateErrorNumber;
}
pass:
SSLFreeBuffer(&signedHashes);
SSLFreeBuffer(&hashCtx);
return err; return ERRCODE;
Would have produced the exact same bug.Thanks in advanced
Of course Python doesn't even have a goto, so the code would have needed to be structured differently to start with.
If I were a betting man I'd wager that this bug wasn't really an accident. It would be really interesting to check commit logs to see the history.
Really? I did something in Python for the first time a while ago and the indentation as code block is something I find very elegant. I can't fathom why would people find something wrong with this.
I think something similar should apply to critical security code. This reminds me of when someone tried to add the following to the Linux kernel:
if ((options == (__WCLONE|__WALL)) && (current->uid = 0)) retval = -EINVAL;
Oops, is that "uid == 0", or is that "uid = 0"? Yet another "typo" that couldn't happen in Python.
if((val = function(args)) != expected)
return val;I'm actually pretty impressed how this bug was not caught before. The compiler warning is just one thing that came to my mind but test coverage should have been the strongest hint. A linter could have also make the thing easier for a code review. Probably these parts of the code should have stricter coding guideline.
Either way, definitely avoidable.
Looks typical of a merge cock up to me as the indentation is preserved suggesting it's a duplicate line or there was an if statement on the previous line that was removed.
> However later code is used as a jump target for goto so it's quite hard for the compiler to infer this
Nope, because a jump target always starts a new basic block.
Not by default. On both GCC and Clang this kind of error isn't caught using -Wall or even -Wextra - you have to explicitly opt-in using -Wunreachable-code. It'd really be nice if that changed and Clang basically had close to -Weverything on by default and required you to opt out, preferably with something like `#pragma ALLOW_SHODDY_<category>` per file to put some pressure on C programmers not to just continue ignoring errors rather than fixing them.
Thanks for the hint. It was amusing to spot the actual bug.
I thought I would hate this model but I absolutely love it. It's the next best thing to pair programming and somewhat less exhausting.
Another clue: indentation fail.
But one thing that pisses me off is that they go and implement SSL and don't have any automated tests for it!!
For a company of Apple's size, that can only be called grossly negligent. There is no excuse. And they probably don't have any automated testing for most of their other code either.
What I would expect is that SSL code is tested with all the different of ways of spoofing a certificate. And that in an automated manner, on every build.
I could see if they were copying & pasting goto statements all over the place, and happened to paste it twice by accident. But that's how it occurred. The second one was added in a separate commit.
I wonder whether the software from the guys at viva64.com would spot that.
However I can't see a valid case for this pattern so static analyser rule to knock it on the head would be a good idea.
clientRandom.data = ctx->clientRandom;
clientRandom.length = SSL_CLIENT_SRVR_RAND_SIZE;
serverRandom.data = ctx->serverRandom;
serverRandom.length = SSL_CLIENT_SRVR_RAND_SIZE;
That is something that I think static analysis tools could signal. It would be a red herring, though.The state of the operation is "success" (err==zero) until some step changes the state to "failure" (non-zero).
The state should be assumed to be "failure" until the last step changes it to "success".
Mixed tabs and spaces, inconsistent indentation, two empty lines in a row, sometimes "if (...)" and sometimes "if(...)".
http://blog.cloudflare.com/red-october-cloudflares-open-sour...
- don't leave local variables uninitialized.
- don't try to hand-optimize lines unnecessarily.
- don't mix assignments into boolean expressions. (Which is really an unneeded optimization.)