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 possible infinite loop #44

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

Conversation

aido
Copy link

@aido aido commented May 4, 2023

Hi,

I am not sure why the share_length and secret_length variables are defined as type uint32_t but both are being compared to a uint8_t in a loop condition. This causes CodeQL to give a high severity security warning. 'High Severity' is probably a bit alarmist but in a loop condition, comparison of a value of a narrow type with a value of a wide type may result in unexpected behaviour if the wider value is sufficiently large (or small). This is because the narrower value may overflow. This can lead to an infinite loop.

See here for further explanation of the warning:
Comparison of narrow type with wide type in loop condition

This PR fixes #42 by casting share_length and secret_length to uint8_t ensuring comparison of same types. If type casting is not the solution then maybe share_length and secret_length should be declared as uint8_t not uint32_t?

Note: I chose to cast to the narrower uint8_t rather than declaring j as the wider uint32_t as I think neither share_length or secret_length should ever be bigger than 255.

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.

CodeQL warnings
1 participant