Ruby Digest::SHA512.hexdigest throws a segment fault and quits in Yosemite

728 views Asked by At

We have an older REE rails app that I work on my local dev environment in OSX Yosemite. I recently switched from Mavericks, with which I had no problems. I ran this app for the first time on my new work mac and found I was unable to login due to it throwing a segment fault error and quitting the local webrick server. After some investigation, I found the culprit:

digest = Digest::SHA512.hexdigest('some_arbitrary_value')

On further investigation, I found that this line of code throws the following error:

[BUG] Segmentation fault
ruby 1.8.7 (2013-06-27 MBARI 8/0x6770 on patchlevel 374) [i686-darwin14.3.0], MBARI 0x6770, Ruby Enterprise Edition 2012.02

...and quits the ruby console.

Both ruby versions 1.8.7 and REE produce this issue on my OSX Yosemite machine. Ruby versions 1.9.3 and newer seem to produce the expected hash without error.

Why does Digest::SHA512.hexdigest produce a [BUG] Segmentation fault error after switching from OSX Mavericks to Yosemite?

3

There are 3 answers

0
user2729127 On

I don't have an answer, but have exactly the same issue.

Interestingly I am moving from a Mac running Yosemite to a brand new Mac also running Yosemite. The old mac does NOT have the seg fault issue. Both machines are using Yosemite, rvm, ruby 1.8.7

But I have noticed that 'new mac' uses openssl 1.0.2c 12 Jun 2015 and 'old mac' uses openssl 1.0.1c 10 May 2012

Could it be something to do with the version of SSL libraries being compiled against?

Sorry for not providing an answer but thought this was worth mentioning in case it helps.

I am continuing to investigate and will report any success here.

Update:

'old mac'

ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'

reports OpenSSL 0.9.8r 8 Feb 2011

'new mac' reports OpenSSL 1.0.2c 12 Jun 2015

0
user2729127 On

Solution:

You need to ensure that ruby is built using an older version of openssl.

I downloaded the 0.9.8 openssl into a directory (~/builds/openssl-0.9.8zg), built it but did NOT install it. When you install a version of ruby, point rvm to the openssl 0.9.8 directory

rvm reinstall 1.8.7-p374 --autolibs=0 --with-openssl=~/builds/openssl-0.9.8zg

This has worked for me and rails 2.3.18 now fires up and runs under Yosemite.

2
Iván González On

I had the same problem with version ree-1.8.7-2012.02 of ruby and Max OS X Yosemite, and as all of the solutions I found on the internet doesn't work for me, after some tests I found a solution.

You only have to change Digest::SHA512.hexdigest(digest) to OpenSSL::Digest::SHA512.new(digest).hexdigest and it will work fine.

It's a little inconvenience because you have to change the code all over your application, but as last resource it works.