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
Feature request: detect malloc(0) dereference #1058
Comments
We've tried that before, (to return NULL on malloc(0), not to return 0x00000012 though) and it caused lots of incompatibilities. Right now, malloc(0) is effectively equivalent to malloc(1) and we don't catch this bug:
I don't think the standard allows us to return a non-null but fixed address for all instances of malloc(0): What we can do, is to still allocate a valid pointer but poison all the memory.
|
We also could:
But I don't know if it's better... probably not... no stacks, free(p + 100) is not detected. |
In my experience, returning NULL from malloc activates code paths that in most software have literally never been tested, leading to all kinds of unexpected behavior. |
malloc(0)
and then dereferencing the acquired pointer is undefined behavior, and I believe that the OpenBSD libc deliberately segfaults in this case.It would be nice if ASAN would return an invalid non-null pointer (eg. 0x00000012) that is guaranteed to crash if dereferenced.
It would help find a class of bugs that might be rare but if present could lead to denial-of-service situations or worse in public facing software.
(Sorry if this has been brought up before)
The text was updated successfully, but these errors were encountered: