May 30, 2006

Have you ever had one of those days?

Oh man... sometimes you just want to grab a keyboard and smack yourself up side the head.

Ok, so time for a little secret.... I'm human. And I can be dumb at times. Not "doh.. I am so smart, 's-m-r-t' smart" kinda dumb. Actual "Dana you should know better" dumb.

Recently found a bug I had in an failure code path which in all accounts, was missed in testing. During a database insertion, I would validate the data. Makes sense, always good to validate the data. One problem. One of the validation checks is to escape single quotes. Ya, except I forgot to call that validation against one of the fields. *sigh* But that wasn't the dumb-dumb part.

What compounded this problem was the fact that this was all done in a database transaction. On failure I would call a rollback, like all good database insertions should. Now for the dumb part... the audit log for this failure... was being inserted into the database in the same bloody transaction. ARGGGGGGGGG. So even though I thought I was being smart in putting the audit log in the failure code path, on a rollback the failed event wasn't inserted into the audit log table at all. No wonder no one caught this.

Gosh I feel dumb. I think I will go crawl into a hole for a bit while the scolding and heckling commenses. I should know better than this.

Moral of the story: ALWAYS test all failure code paths, and make sure code coverage can prove you are going down that tree.

Posted by SilverStr at May 30, 2006 10:39 AM | TrackBack
Comments

Always there's a smart-arse who asks you "what if you have an error in your error-handling code?", and you usually have to say "at that point, we drop everything". At least, that's the polite way to deal with it.
The not-so-polite method is to say "great idea - how about you write an error-handler for that", and keep telling them that until they understand the term "guaranteed stack overflow by infinite recursion".
Of course, even the smartest of developers will occasionally find themselves coding an error in the error handler that causes them to hit the error handler again. I do have to ask - why does the error log reside on a device that supports roll-back? The ideal error log is printed on a roll of line-printer paper, so that an attacker can't roll the log back to hide the error condition they abused to get into the program.
Does that count as a heckle or a scold?

Posted by: Alun Jones at June 1, 2006 03:45 PM

P.S. You mis-spelled "commences" :-)

Posted by: Alun Jones at June 1, 2006 03:46 PM

I think it counts as both :P

And muh spelun is gust fine thank ya very much. Ok, maybe not. I wish MT had spell check *sigh*

Posted by: Dana Epp at June 1, 2006 04:04 PM