sass / sassc-ruby

Use libsass with Ruby!
MIT License
367 stars 156 forks source link

Handle non-StandardError in custom functions #245

Open kolen opened 6 days ago

kolen commented 6 days ago

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.