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
$ 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 =
SSLHashSHA1 = do def update(*) end; alias final update

# 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) if ((err =, hashOut)) != 0);

puts "Verified" # never reached
# ...

puts "Failed";

Executing this with gotoruby:

$ rvm use 2.2.2-goto
$ ruby gotofail.rb

Further Reading

More Idiosyncratic Ruby