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 crash when attempting to dow-cast nullptr in debug builds #315

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

egiurleo
Copy link

@egiurleo egiurleo commented Oct 30, 2024

Motivation

In our debug builds, our down_cast helper verifies that the pointed-to node actually is the kind of node we're trying to cast it to. Doing this requires us to check the type field, which will fail if given nullptr.

We modify the ENFORCE check to either:

  1. Allow nullptr
  2. otherwise nullptr, check for the correct type.

This is safe because of the short-circuiting behaviour of ||.

Test plan

Automated tests continue to pass

@egiurleo egiurleo self-assigned this Oct 30, 2024
Copy link

@amomchilov amomchilov left a comment

Choose a reason for hiding this comment

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

I hope the down cats cheer up

image

parser/prism/Helpers.h Outdated Show resolved Hide resolved
@egiurleo egiurleo changed the title nullptr check during downcast nullptr check during ENFORCE in downcast Oct 30, 2024
@amomchilov amomchilov changed the title nullptr check during ENFORCE in downcast Fix crash when attempting to dow-cast nullptr in debug builds Oct 30, 2024
In our `downcast` helper, we check that the node argument is actually
a Prism node. However, doing this requires us to check the `type` field,
which will fail if the node is a `nullptr`. By doing a `nullptr`
check in the `ENFORCE`, we guarantee we won't crash by checking for
a field on a `nullptr`.

Co-authored-by: Alex Momchilov <[email protected]>
@egiurleo egiurleo merged commit c983396 into prism Oct 31, 2024
1 check passed
@egiurleo egiurleo deleted the emily/downcats branch October 31, 2024 13:46
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.

3 participants