Feeds

Today's bugs have BRANDS? Be still my bleeding heart [logo]

Code-slinger Verity reviews the rash of groovy-named open-source security vulns

Security for virtualized datacentres

Stob In view of the ongoing security-holed far-too-open source situation, I have decided to convene an emergency meeting of ERCOCC, the El Reg Committee Of Competent Coders, to review what has occurred and how we should go forward.

No time for chitter-chattering. Settle down everybody, and juice up the PowerPoint projector please Eric.

Bug #1: Goto Fail

The last time I spotted a goto in the wild was about 15 years ago. It was embedded in a C++ date-time class I had lazily poached from a certain code-sharing site, where the file had been made available under the controversial WYGIWYD licence (What You Get Is What You Deserve).

That use of goto was quite gratuitous. It shone in the source out like the bright colourings adopted by certain venomous insects to warn birds not to eat them. And, like the stupidest, freshly-fledged squab, I inhaled the wasp and endured the consequences. Needless to say, it would have been quicker and more fun to copy out Letts 2002 Diary for the Dimmer Bulb by hand.

Because nobody uses goto in real code, right? Sure, back in the day, Donald Knuth - not an obvious Nigel Farage-stylee hero of reactionary principles - bashed out a quick paper in its defence. But that was in 1974, when digital watches were still a pretty neat idea, smoking fags was both funny and clever and certain Top of the Pops presenters blah-di-blah ugh.

So - and I'm sure you got here before me - when the Goto Fail SSL kerfuffle occurred, you could have smacked my gob into last Tuesday with a bent feather. Naturally I clicked through the links to the C file in question: go here and scroll down to SSLVerifySignedServerKeyExchange to see for yourself, or here for a grown up analysis.

Or, to save time and excess clickage, take a gander at this dramatic reconstruction. See if you can spot that problematic line:

OSStatus SSLVerifySignedServerKeyExchange(/*loadsa params*/)
{
    /* Declare some local variables, including: */
    SSLBuffer       signedHashes;
    /* More mucking about with local variables, eg */
    signedHashes.data = 0;
    /* Then the main rhythm of the function: */
    if ((err = SSLImportantManInTheMiddleDefence(hashCtx, otherStuff)) != 0)
        goto fail;
    if ((err = SSLBitTwiddlingBogeymanBaffling(whatever)) != 0)
        goto fail;
    if ((err = SSLTumTittyTumTum(tum)) != 0)
        goto fail;
    if ((err = SSLNotForYourTinyBrainYouEarthling(params)) != 0)
        goto fail;
    if ((err = SSLAnotherFunctionYouDontUnderstand(hohoHo)) != 0)
        goto fail;
    /* ... */
    /* After many more lines of the same ilk: */
    if ((err = SSLYadaYadaYada(stuff)) != 0)
        goto fail;
        goto fail;
    if ((err = SSLDoTheActualImportantCheck(stuff)) != 0)
        goto fail;
fail:
    SSLFreeBuffer(&signedHashes);
    SSLFreeBuffer(&hashCtx);
    return err;
}

With its repeated goto fail refrain, the code's structure seems familiar. Ah yes, I know: the bawdy song Three German Officers crossed the Rhine. Substitute 'goto fail' for 'parlez-vous' and you can practically whistle it:

if err equals ess ess ell tum-tee-tum
  goto fail,
if err equals ess ess ell tum-tee-dum
  goto fail...

The repeated goto is like the phrase "Simon says" in a game of "Simon says": it exists only to trip you up. It makes for a bored, twitchy style.

Programmers shouldn't be inflicting boring, repetitive tasks on themselves. That's why they make friends with computers.

And this goto just isn't necessary. Despite the non-comittal line taken by this page, there are better ways to do it.

For example, the code maintainer could simply drop the gotos and code the whole lot with nested ifs. Sure, he would likely want to refactor the function into smaller pieces, to avoid ending up with his logic uncomfortably cramped up against the right hand margin, like the face of a hungry child squished against a restaurant window in a heart-warming movie. But so what? This program could use a little extra reorganisation.

Or - and this is Baby's favoured solution - he could just turn on the C++ switch of that great big compiler he has there, and protect his resources with a bit of RAII. With that in place, his ghastly gotos become happy returns.

Reader: Is there any other feature to which you would wish to draw my attention?

Stob: To the curious incident of the signedHashes variable in the body of the function.

Reader, gamely playing along: But the signedHashes variable does nothing in the body of the function.

Stob, triumphantly: That is the curious incident.

Providing a secure and efficient Helpdesk

Next page: Bug #2: GnuTLS

More from The Register

next story
Preview redux: Microsoft ships new Windows 10 build with 7,000 changes
Latest bleeding-edge bits borrow Action Center from Windows Phone
Google opens Inbox – email for people too thick to handle email
Print this article out and give it to someone tech-y if you get stuck
Microsoft promises Windows 10 will mean two-factor auth for all
Sneak peek at security features Redmond's baking into new OS
UNIX greybeards threaten Debian fork over systemd plan
'Veteran Unix Admins' fear desktop emphasis is betraying open source
Entity Framework goes 'code first' as Microsoft pulls visual design tool
Visual Studio database diagramming's out the window
Google+ goes TITSUP. But WHO knew? How long? Anyone ... Hello ...
Wobbly Gmail, Contacts, Calendar on the other hand ...
DEATH by PowerPoint: Microsoft warns of 0-day attack hidden in slides
Might put out patch in update, might chuck it out sooner
prev story

Whitepapers

Choosing cloud Backup services
Demystify how you can address your data protection needs in your small- to medium-sized business and select the best online backup service to meet your needs.
Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.