A C++ Challenge
chargen.matasano.com
chargen.matasano.com
Using NULL, inconsistent indenting, putting int i outside the for loop, struct's that should be a class and a class that has no reason being a class. Not to mention variables like 'o'* and a class named Obj (woo saved 3 letters and named it the most generic thing I could think of). one struct starts with a _ the other does not... using printf rather then cout. Bad variable naming in general.
And this is all before even reporting the real issues which from the looks of it are more with the c code then the c++ code.
* o does not stand for object, but objects making it an even worse sin
Isn't that what security researchers sometimes have to face -- horrid code that's used by thousands of people anyways? They're not there to judge whether it's nice and properly indented or not, only if it's exploitable...
Also, in C++ NULL == 0, it doesn't matter if you use the defined value or not.
There is nothing wrong with C-like C++ code. Nothing at all.
On the other hand, recognising that C and C++ treat 'unsigned' differently, and that certain C code may be wrong C++ code... A C/C++ coder who does not recognise that C++/C have different behaviour in certain cases is not much of a coder. (Hm, I believe that's actually one of the rare occasions when saying C/C++ is correct.)I assume that's the bug in this code - it's neither idiomatic C++, nor is it C, but written in a manner that brings out the neatfreak in me.
Chris and Thomas: something like coverity should catch this particular bug without trouble. Have you guys verified this?
Really it is just another hint that this is made by a C programmer.
Fix the hygiene and then lets talk about the actual code
Now you're starting to see what a nightmare these problems are for developers.
, or rewrite this code to use proper checking of untrusted data. I don't know the specifics of your code audits, but the only verdict for the code like this should be to redo it.
If the client is uncooperative or if the reviewer has spare time, then, yeah, try and find the actual exploit. Perhaps, if it is an interview question, it's understandable too. Other than that I don't see a clear reason for going this deep into analyzing dirty code. It may or may not contain an exploitable bug, so just clean it up and move on.
if(argv[1] == NULL)
Once I know where the problem is coming from, I can change the affected routines in such a manner that they don't cause the same error.
If I faced such a problem in the real world, it would take too long to really understand the bug. It's much faster to isolate the bug and then force a whole big area of the code out and rewrite it in a different and simpler manner that would not cause such a bug.
I think an attitude of trying to leap over gaps in your knowledge is really destructive. Where do you draw the line at "this is too much trouble to understand, I just won't bother?" It's our job to understand the machine to the best of our ability.