Signed integer overflow - #1324
Conversation
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
0176824 to
0b5f4f4
Compare
0b5f4f4 to
041fd37
Compare
|
Thanks, Changing Why logic looks good at first glance though. |
😄 I'll change back!
To not lock-in any assumptions about the width since mostly native types are used elsewhere. Also
Great, thanks! I'll clean it up in a few hours! |
041fd37 to
e01745c
Compare
Changed |
e01745c to
0f5c4ba
Compare
On platforms where long is 32 bit, the multiplication with 1000 causes UndefinedSanitizer to report signed integer overflows: net.c:283:24: runtime error: signed integer overflow: 19994637 * 1000 cannot be represented in type 'long int' This change makes sure that the calculation is made using uint_least64_t and also makes sure that poll() isn't called with a value larger than INT_MAX, which a long (and uint_least64_t) may hold. Signed-off-by: Ted Lyngmo <ted@lyncon.se>
0f5c4ba to
3e91d33
Compare
|
@michael-grunder Another thing I didn't notice before (since I haven't tested on Windows): |
Yes, return (long long)GetTickCount64();Which supposedly returns the number of milliseconds since boot docs. Seems like pretty much what we want here. |
Indeed, that's even cleaner! Do you want me to add that to this PR? |

Make signed integer overflow in redisPollMillis less likely
On platforms where long is 32 bit, the multiplication with 1000 causes UndefinedSanitizer to report signed integer overflows:
This change makes sure that the calculation is made using
uint_least64_tand also makes sure thatpoll()isn't called with a value larger thanINT_MAX, which along(anduint_least64_t) may hold.Note
Medium Risk
Touches connection timeout/polling logic used during socket connect; while intended to be behavior-preserving, changes to time calculations and EINTR handling could subtly affect connect timeouts across platforms.
Overview
Reduces the chance of signed integer overflow in connection timing code by switching timeout and monotonic-time calculations from
longtoint_least64_t(usingINT64_C(1000)multipliers) and adding<stdint.h>.Hardens
redisContextWaitReadyby clamping thepoll()timeout argument toINT_MAXand recalculating remaining time afterEINTR, ensuring large configured timeouts don’t pass out-of-range values topoll()while preserving overall deadline behavior.Written by Cursor Bugbot for commit 3e91d33. This will update automatically on new commits. Configure here.