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

Avoid segfaults when using randomly generated array indexes in items.cpp #2762

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ephphatha
Copy link
Contributor

The first couple of commits set up helpers for future checks. Items.cpp was one of the easier wins, drlg1.cpp is probably the worst offender so I'm trying to avoid that one as long as possible 😂

@@ -1445,7 +1459,7 @@ int RndUItem(MonsterStruct *monster)
}
}

return ril[GenerateRnd(ri)];
return ril[GenerateNonNegativeRnd(ri)];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seemed like the safest way to handle this, I don't think reading invalid memory was actually useful for any generated items but it may break compatibility. That said, with the way it was working previously any unrelated code change potentially could've broken compatibility, no way to know without tests for the exceptional case.

Source/items.cpp Outdated Show resolved Hide resolved
@ephphatha ephphatha marked this pull request as draft August 31, 2021 14:26
@ephphatha
Copy link
Contributor Author

Lets fix all these signed/unsigned comparisons 🙃

Force template type to satisfy 3ds/android builds
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.

1 participant