Skip to content

#21 call asan on setjmp#22

Open
balupillai wants to merge 4 commits into
mainfrom
lua-21
Open

#21 call asan on setjmp#22
balupillai wants to merge 4 commits into
mainfrom
lua-21

Conversation

@balupillai
Copy link
Copy Markdown
Contributor

@balupillai balupillai commented Apr 2, 2026

Note

Low Risk
Low risk: behavior changes only under __SANITIZE_ADDRESS__, but it touches the core longjmp-based error/exception path during ASAN-instrumented builds.

Overview
When compiling with AddressSanitizer (__SANITIZE_ADDRESS__), thrlua.h now maps lua_do_setjmp/lua_do_longjmp to the system setjmp/longjmp instead of the custom assembly implementations.

This lets ASAN intercept the jump functions and correctly unpoison skipped stack frames, reducing ASAN false positives during Lua error handling.

Reviewed by Cursor Bugbot for commit 18b1507. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/luaconf.h Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Lua’s longjmp-based error handling to better cooperate with AddressSanitizer by invoking an ASan “no return” hook before performing longjmp.

Changes:

  • Adds a declaration for __asan_handle_no_return.
  • Wraps LUAI_THROW (for _longjmp/_setjmp and longjmp/setjmp configurations) to call __asan_handle_no_return() before lua_do_longjmp.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/luaconf.h Outdated
Comment thread src/luaconf.h
Comment thread src/luaconf.h
@balupillai
Copy link
Copy Markdown
Contributor Author

DON'T DELETE

Comment thread src/thrlua.h
*/
#if defined(__SANITIZE_ADDRESS__)
# define lua_do_setjmp setjmp
# define lua_do_longjmp longjmp
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASAN detection misses Clang before version 21

Low Severity

The ASAN check uses only __SANITIZE_ADDRESS__, which GCC has supported since 4.8 but Clang only added in version 21 (2026). Clang versions before 21 use __has_feature(address_sanitizer) instead. Builds with older Clang and -fsanitize=address will silently skip this block and continue using the custom asm setjmp/longjmp, defeating the purpose of the ASAN fix. The common portable pattern checks both: defined(__SANITIZE_ADDRESS__) || (defined(__has_feature) && __has_feature(address_sanitizer)).

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 27c45ad. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 18b1507. Configure here.

Comment thread src/thrlua.h
*/
#if defined(__SANITIZE_ADDRESS__)
# define lua_do_setjmp setjmp
# define lua_do_longjmp longjmp
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASAN path incorrectly triggers extern declarations for setjmp

Medium Severity

When __SANITIZE_ADDRESS__ is defined, lua_do_setjmp is #define'd to setjmp before the #ifdef lua_do_setjmp guard on line 239, causing the extern declaration block (designed for custom asm symbols) to be entered. The declarations expand through the platform's setjmp macro — on glibc this happens to produce a valid _setjmp re-declaration, but on platforms where setjmp(env) expands to e.g. sigsetjmp(env, 1), the result is invalid syntax. The ASAN path duplicates the intent of the #else fallback on lines 243–245 but inadvertently goes through the wrong code path.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 18b1507. Configure here.

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.

2 participants