-
-
Notifications
You must be signed in to change notification settings - Fork 905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefer libxml2's strdup and strchr equivalents #1517
Conversation
Background: it seems like some platforms may not actually behave nicely if you use |
Thanks for submitting this! Do you have a way to reliably reproduce the segfault? I'd like to verify On Jul 27, 2016 6:35 PM, "Aaron Patterson" [email protected] wrote:
|
Hmm, ok, now that I'm looking at the diff maybe that's not necessary. |
@flavorjones Confirm; the segfault is unrelated. I'm seeing libc Using the |
@jeremy I'm not sure if you still think this should be merged? Your most recent comment above seems to indicate that the problem you're trying to solve may be unrelated? |
Yes, it should. I've been running this in production for months now and it completely solves the issue I hit. Here's the problem I was troubleshooting: "using libc This patch obviates the root issue with This is good hygiene as a user of libxml in any case, too! (That said, being able to segfault at all here is troubling. We aren't doing any error checking.) |
(Working around a puzzling segfault when using libc strdup on a C string from Ruby.)
@jeremy Thanks so much for submitting this and for persisting. Merging! |
Caused by compiler confusion about what to export from string.h, depending on ANSI/ISO C standards used. When strdup isn't exported, GCC provides a builtin. When cross-compiled for another platform, this can lead to returning a 32-bit pointer instead of 64-bit -> segfault. Fix by including ruby/util.h which unsets and redefines strdup as ruby_strdup, a portable implementation. Further reading * https://stackoverflow.com/questions/8359966/strdup-returning-address-out-of-bounds * https://bitbucket.org/einsteintoolkit/tickets/issues/1816 Similar issue affected Nokogiri, with a similar fix: * sparklemotion/nokogiri#1517
Caused by compiler confusion about what to export from string.h, depending on ANSI/ISO C standards used. When strdup isn't exported, GCC provides a builtin. When cross-compiled for another platform, this can lead to returning a 32-bit pointer instead of 64-bit -> segfault. Fix by including ruby/util.h which unsets and redefines strdup as ruby_strdup, a portable implementation. Further reading * https://stackoverflow.com/questions/8359966/strdup-returning-address-out-of-bounds * https://bitbucket.org/einsteintoolkit/tickets/issues/1816 Similar issue affected Nokogiri, with a similar fix: * sparklemotion/nokogiri#1517
Background: Working around a puzzling segfault when using libc strdup on a C string from Ruby. Returns a pointer that's outside the program heap entirely.
Turns out libxml2 provides its own strdup/strchr equivalents that use the mem management functions we pass it (including ruby's malloc, ruby_strdup, etc), so may as well prefer these anyway.