-
Notifications
You must be signed in to change notification settings - Fork 196
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 integer overflow #555
Conversation
7eadb47
to
4ca2f5d
Compare
Wat? https://github.com/libtom/libtommath/actions/runs/5144260217/jobs/9260336791?pr=555#step:4:333
Do I understand this correctly that |
Yes, it is a good boy^WPRNG. Found it at three places in test.c , so it isn't that bad. |
I just thought whether it'd be good to add runtime checks&fixups to the |
Changing the output of a PRNG is always *hng* for me but is probably the easiest. How about offering |
absolutely! |
Alhaalta ylös! ;-) Copy&paste a check into every single |
(cherry picked from commit beba892)
4ca2f5d
to
be78ab9
Compare
`abs()` can only convert `INT_MIN-1 .. -1` to a positive `int`. Nothing prevents the PRNG to create `INT_MIN` which then leads to a failure of the call to `abs()` as seen in [0]. Instead add an unsigned version of the function reading from the PRNG, so we also don't need to make an absolute value from it. [0] #555 (comment) ``` demo/test.c:1112:13: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself ``` Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
`abs()` can only convert `INT_MIN-1 .. -1` to a positive `int`. Nothing prevents the PRNG to create `INT_MIN` which then leads to a failure of the call to `abs()` as seen in [0]. Instead add an unsigned version of the function reading from the PRNG, so we also don't need to make an absolute value from it. [0] #555 (comment) ``` demo/test.c:1112:13: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself ``` Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
69b30b1
to
11f1acd
Compare
`abs()` can only convert `INT_MIN-1 .. -1` to a positive `int`. Nothing prevents the PRNG to create `INT_MIN` which then leads to a failure of the call to `abs()` as seen in [0]. Instead add an unsigned version of the function reading from the PRNG, so we also don't need to make an absolute value from it. [0] #555 (comment) ``` demo/test.c:1112:13: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself ``` Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
11f1acd
to
6175cca
Compare
In a next step we should follow up on #430 ff. |
This is #546 but on develop.