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 when siphoning a vehicle with multiple tanks #40227

Merged
merged 2 commits into from
May 6, 2020

Conversation

nphyx
Copy link
Contributor

@nphyx nphyx commented May 6, 2020

Summary

SUMMARY: Bugfixes "fixes segfault when attempting to siphon from vehicle with multiple tanks"

Purpose of change

When siphoning from a vehicle with more than one tank and the first tank is empty, during the check to auto-select the first tank with contents, a null pointer would be returned from pt.base.contents.legacy_front() ultimately resulting in a segfault.

Describe the solution

Remove the legacy_front() call and replace it with a proper !empty() check and only_item() call.

Describe alternatives you've considered

N/A

Testing

First start a fresh game, give yourself a jerrycan and a hose (and then remove the hose from the jerrycan ...), go find a vehicle with 2 fuel tanks, siphon the first, and then siphon the second. You should see a segfault.

Apply patch, repeat, no more segfault.

Additional context

This legacy_front() thing is extremely unsafe and may be the cause of several other crashes I'm seeing during playtesting. I put a debugmsg in it when it's about to return a nullptr, because this is almost always going to result in undefined behavior and this should help narrow down when this was the proximate cause.

src/item_contents.cpp Outdated Show resolved Hide resolved
Co-authored-by: Curtis Merrill <curtis.r.merrill@gmail.com>
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