ohler55 / agoo

A High Performance HTTP Server for Ruby
MIT License
912 stars 39 forks source link

rb_rescue2(..., 0) is incorrect and can cause segfaults #84

Closed eregon closed 4 years ago

eregon commented 4 years ago

Initially, we got this bug report https://github.com/oracle/truffleruby/issues/1823 and created this spec: https://github.com/ruby/ruby/blob/34b0a7be0ed2fd4ca4d1d509a22964b5e61dfe34/spec/ruby/optional/capi/ext/kernel_spec.c#L183-L196

However, that spec reliably segfaults on MRI, and so had to be disabled https://github.com/ruby/ruby/commit/6eb3820aad1668b6b09c68929840dff2cfda04c0

All usages of rb_rescue2(..., 0) should be replaced by rb_rescue2(..., (VALUE)0) as the documentation says: https://github.com/ruby/ruby/blob/34b0a7be0ed2fd4ca4d1d509a22964b5e61dfe34/eval.c#L950

Notably there are some usages in https://github.com/ohler55/agoo/blob/395522a1ca64d286e7a4a895f19f1e98bbe79d26/ext/agoo/rserver.c#L387

cc @aardvark179 @mame

ohler55 commented 4 years ago

Interesting. I guess it makes sense since VALUE is 64 bit and on a 32 bit system a naked 0 would be 32 bit. Release Agoo 2.12.3 with the fix.

eregon commented 4 years ago

Thanks for the quick fix! (9c0a5c71f16ef62009e302414a15a32e42ca19db)