Skip to content
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

Handle non-StandardError in custom functions #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kolen
Copy link

@kolen kolen commented Jul 2, 2024

fixes #244

When exception that is not a subclass of StandardError happens inside custom sass function, it's not handled by SassC::FunctionsHandler and gets raised up to FFI::Function block body, where ffi gem silently catches it and treats as if block returned nil. This causes segmentation fault later in C code, when trying to dereference null pointer.

This changes rescue in functions_handler to handle all exceptions.

Recovering from non-StandardError might be not a good idea in general (for example when exception is NoMemoryError), but I didn't find proper ways to abort the whole process inside ffi callback. Tried Kernel#abort, it just prints error message and causes callback to return nil so the same segfault remains. Maybe using abort() libc function directly is an option but I doubt if it's portable enough between systems. So, I think, rescuing all exceptions is okay here.

Prevent segmentation fault due to returning null pointer when
non-StandardError exception is raised in custom functions. Abort with
error message instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault in sass_value_get_tag() when custom function raises non-StandardError
1 participant