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

[C++] Undefined behaviour in exception handling #191

Open
haaawk opened this issue Mar 14, 2018 · 1 comment
Open

[C++] Undefined behaviour in exception handling #191

haaawk opened this issue Mar 14, 2018 · 1 comment

Comments

@haaawk
Copy link

haaawk commented Mar 14, 2018

There is a potential null pointer dereference here: https://github.com/antlr/antlr3/blob/master/runtime/Cpp/include/antlr3exception.inl#L315

m_expectingSet is very often null. It should be checked before doing anything with this pointer.

Currently it leads to undefined behaviour and sometimes crashes of the whole program.

@strfry
Copy link

strfry commented Jun 26, 2018

An additional explanation: The bitsetLoad() function tries to work around being called with a NULL this pointer:

Apparently this still undefined behaviour, and recent GCC versions assume this to be non-null and optimize this check away, with a warning:
include/antlr3cpp/antlr3bitset.inl:54:2: warning: nonnull argument ‘this’ compared to NULL [-Wnonnull-compare]

~~The only workaround I see is probably to manually change every line where bitsetLoad() might be called with a NULL pointer. ~~

The GCC 6 Release Notes describe this issue as a consequence of Value range propagation, -fno-delete-null-pointer-checks can be used as a compiler flag to keep the old code working.

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

No branches or pull requests

2 participants