Goto Fail

If you change one line in Ruby's source, it will support goto statements!

You can install a patched version via RVM's patch feature:

$ rvm install 2.2.2 -n goto --patch http://git.io/vfxF2
$ rvm use 2.2.2-goto

What to do to play around with this new feature? Let's reimplement this famous bug in Ruby:

# prepare some dummy data
hashCtx = hashOut = clientRandom = serverRandom = signedRandom = Object.new
SSLHashSHA1 = Class.new do def update(*) end; alias final update end.new

# how the goto fail bug would look like if it was implemented in ruby
__goto__(:fail) if ((err = SSLHashSHA1.update(hashCtx, clientRandom)) != 0);
__goto__(:fail) if ((err = SSLHashSHA1.update(hashCtx, serverRandom)) != 0);
__goto__(:fail) if ((err = SSLHashSHA1.update(hashCtx, signedParams)) != 0);
__goto__(:fail);
__goto__(:fail) if ((err = SSLHashSHA1.final(hashCtx, hashOut)) != 0);

puts "Verified" # never reached
# ...

__label__(:fail);
puts "Failed";

Executing this with gotoruby:

$ rvm use 2.2.2-goto
$ ruby gotofail.rb
Failed

Further Reading

More Idiosyncratic Ruby