r/programming • • Apr 09 '14

Theo de Raadt: "OpenSSL has exploit mitigation countermeasures to make sure it's exploitable"

[deleted] — view deleted post

2.0k Upvotes

661 comments sorted by

View all comments

Show parent comment

163

u/emergent_properties Apr 09 '14

But remember The Linux Backdoor Attempt of 2003

A malicious bug can hide in 1 line of code in plain sight.

Looking complex is not even necessary.

77

u/zjm555 Apr 09 '14

I do indeed remember that :) This is why some teams rigidly enforce, as a coding style rule, that comparisons against literals always have the literal on the left-hand side.

67

u/[deleted] Apr 09 '14

54

u/DarkNeutron Apr 09 '14

Several bugs have I written that this would catch...

42

u/tequila13 Apr 09 '14

As someone who had to maintain Yoda-style code, that's not funny.

43

u/GratefulTony Apr 09 '14

funny: it is not.

12

u/gthank Apr 09 '14

Yoda code is trivial to read. There are any number of other coding idioms that suck more.

→ More replies (7)

3

u/flying-sheep Apr 10 '14

Wouldn't a static code analysis that detects assignments where conditions are expected have the same effect?

→ More replies (1)
→ More replies (1)

45

u/syncsynchalt Apr 09 '14

I prefer to trust the compiler's warnings on this one. I've had to maintain yoda code and it's terrible to read.

29

u/zjm555 Apr 09 '14 edited Apr 09 '14

I agree that it's worse to read. A good style checker that will cause an automated test to fail is my preference. My style rule is simply "no assignment inside an if statement".

12

u/dnew Apr 09 '14

It's only terrible if you're not in the habit.

I always use < instead of >, rearranging the order of the comparison if necessary. Because then the small things come before the big things. (Good for stuff involving timestamps, especially.) I find it hard to read code that does things like "if (x < y || z > w)" and figure out what it means, without thinking about it, without verbalizing it.

8

u/[deleted] Apr 09 '14

So you write

if (300 < score && score < 500 || 1000 < time)

instead of

if (score > 300 && score < 500 || time >= 1000)

? There's a special place in hell for people like you.

14

u/kzr_pzr Apr 09 '14

300 < score && score < 500

I do it the same way, it's easy to see the boundary values of interval.

5

u/[deleted] Apr 09 '14

In this particular case, yes, I think so, too, but what about the part about || 1000 < time? This is why if there is one thing that's being tested against another, I put the thing that's tested first. Otherwise I put them in the logical order in which they come (eg, player1.score > player2.score or time(before) < time(after))

→ More replies (3)

4

u/wwqlcw Apr 09 '14 edited Apr 09 '14

It very naturally reads as "if score is between 300 and 500." I like it, I think it's much easier to read than your alternative. The code actually becomes a graphical representation of the condition in this case.

I don't know about "always use <" though.

→ More replies (5)

27

u/IICVX Apr 09 '14 edited Apr 09 '14

Unfortunately some people try to enforce that sort of thing in languages that aren't C and C++, where you'll actually get type errors because you're trying to put an integer or something where a boolean should go.

Edit: though to be fair, you do see that sort of thing in Java with the whole CONSTANT.equals(variable) thing, but that's just due to Java's handling of the billion dollar mistake.

3

u/[deleted] Apr 09 '14

Any chance of getting a non-flash version of that? Mine keep crashing.

→ More replies (1)
→ More replies (1)

5

u/BonzaiThePenguin Apr 09 '14

This was probably a big issue back in 2003 and until fairly recently, but the compilers I use these days warn if you assign without putting parentheses around it.

if (x = 5); // warning
if ((x = 5)); // okay
→ More replies (9)

25

u/[deleted] Apr 09 '14

I propose we brand the phrase "given enough eyeballs all bugs are shallow" the Linus Fallacy.

36

u/emergent_properties Apr 09 '14

I think the problem was that everyone assumed eyeballs were already looking at the problem.. and that assumption ran somewhat flat. I honestly feel that's outside the issue of if it was open sourced or closed source..

People weren't looking!

→ More replies (8)

17

u/peabody Apr 09 '14

Wasn't it Eric Raymond who said this, not Linus?

4

u/gthank Apr 09 '14

He named it after Linus, if I'm not mistaken.

→ More replies (1)

6

u/TinynDP Apr 09 '14

I think its less of a fallacy for Linux. More people look at core Linux systems than look at OpenSSL.

5

u/elmindreda Apr 09 '14

Sadly, probably because Linux is readable.

→ More replies (5)
→ More replies (4)