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

Fix segfault (null deref) in named initialisation of nested anonymous union #156

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

Conversation

el-remph
Copy link

This seems very specific but I did happen upon it organically. What were the chances? lol

Also adds a regression test, which causes previous chibicc version to deref NULL and segfault (the cc1 process dies with SIGSEGV, which causes the driver to exit(1)).

I think I'm right to assume that the only way mem->name can be NULL is if mem is an anonymous union/struct? Just wanted to make sure

@fuhsnn
Copy link

fuhsnn commented Feb 11, 2025

mem->name will be null for unnamed bitfields too, for example this will trigger the newly added assert:

struct { int : 7; int foo; } s = {.foo = 0};

IMO unnamed bitfields should be filtered out earlier though.

@el-remph el-remph force-pushed the anonymous-union-segfault branch from f7f4305 to f17f6be Compare February 14, 2025 03:57
@el-remph
Copy link
Author

@fuhsnn Thanks, I hadn't thought of that. Added that to the test, and fixed the code to allow it, and still prevent mem->name->len from being reached if mem->name is NULL

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