Recent CodeSOD

Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.

Sep 2008

The Magic Wand of Generic

by in CodeSOD on

J. K.'s boss loves the term "generic." Developing a feature that prompts if one specific field is left blank, that will only be used on that page? Make it generic enough to work on any page. Working on an application that will only ever be used by the local government in Podunk, MA? Make it generic enough to be able to easily change every line of text into Swahili, just in case. He didn't know the ins and outs of what was involved to make this possible, he just wanted his team to wave their collective genericification wand over the application's code.

This is precisely why he was so upset when an email form that was supposed to be generic wasn't working all of the time. It had been built to convert any HTML form with a properly named From, To, and Subject line into an email. And it worked for the most part, until they tried to apply it to a new form with more fields than others that used the control.


Constantly Expanding

by in CodeSOD on

Close your eyes for a moment and visualize with me. (Hopefully you have text-to-speech turned on.) I want to try some guided imagery on you.

Your daily grind is over. You're no longer maintaining a huge application that your whole team hates. You're sitting alone in a peaceful meadow. There is a small mailbox here. Your computer is in front of you, and your favorite IDE is loaded up on the screen. You're starting a new project — a project in which you will guide the overall design. Your business rules are well-defined and you know them like the back of your hand.


syntax.vb

by in CodeSOD on

For nearly two years, Hank T. tried his best to avoid the CEE system. He even made an effort to not know what CEE stood for (though he was pretty sure it was Customer something Engagement). But alas, the inevitable happened and he was finally tasked with fixing a bug in CEE.

Years ago, the CEE system was created by a developer who lived by The One Rule: there are no rules, not even The One Rule. And not surprisingly, his code showed for it. To investigate the bug he was assigned to fix -- Customer Versions aren't sorting properly -- Hank dove in to CustomerClass.vb, one of the thousands of VisualBasic.NET code files that made up the application.


Keeping It Stupid Simple

by in CodeSOD on

"Not too long ago," writes R.S., "a coworker left the company for greener pastures. His motto was Keep It Simple and, until now, I wasn't sure how simple he liked things."

"This is one of my favorite snippets of PHP code from his own, unique authentication process."


SQL Injection Protection * 3

by in CodeSOD on

SQL Injection seems to be a pretty common theme around here on TDWTF. It's not so much pointing out SQL Injection vulnerabilities (aside from that one state that leaked a whole bunch of SSNs), but instead exploring all those "unique" ways that developers try to address the problem. Well, here are three more to add to the mix.

"I found this particular snippet in the external sales portal at my company," wrote Ben, "it's a technique that appears throughout the site in various queries. This was their attempt to protect the database from SQL injection attacks."


My str_replace() Can Beat Up Your str_replace()

by in CodeSOD on

There was a small bug in the PHP order form that Jared L. had developed: the form would complain that "$1000" is an "invalid numeric value." While technically true, Jared's boss wanted to make the form as fool-proof as possible, and asked Jared to fix it.

"No problem," Jared affirmed, "I'll make sure to have it strip those out."


Classic WTF: The Phantom of The System

by in CodeSOD on

It's a particularly busy week for me: on top of a few looming deadlines, I'll be at Business of Software 2008 in Boston. So, I figured it'd be the perfect opportunity to revisit some classics.

The Phantom of The System was originally published on August 2nd, 2005.



Classic WTF: To the Hexth Degree

by in CodeSOD on

It's a particularly busy week for me: on top of a few looming deadlines, I'll be at Business of Software 2008 in Boston. So, I figured it'd be the perfect opportunity to revisit some classics.

To the Hexth Degree was originally published on March 24th, 2006 and, to this day, it still holds the title of the Worst Hexadecimal Conversion Routine.