Re:Git Security Vulnerabilities Announced
by kgeist on Tuesday January 17, 2023 @02:46PM
(#34417687)
I'm quite paranoid about integer overflows, so in my hobby projects I now have a habit of always using helper functions (which generate an error on overflow) instead of "bare" math operators, and whenever I see a bare math operator without any checks in an open source project (and from what I've seen almost no one checks for them) I wonder whether they thought about potential consequences or I'm being too paranoid
[ Parent
| on HN ]
Re:Git Security Vulnerabilities Announced
by sshine on Tuesday January 17, 2023 @03:48PM
(#34418796)
My contribution to two open-source projects in recent years has involved a transition to the use of safe arithmetic, too.
I think it makes a lot of sense to think about. Ultimately, it matters more in some applications than in others.
Re:Git Security Vulnerabilities Announced
by soiler on Tuesday January 17, 2023 @03:54PM
(#34418904)
Can you explain this as if I were a programmer who doesn't know what that looks like?
Re:Git Security Vulnerabilities Announced
by favorited on Tuesday January 17, 2023 @04:24PM
(#34419420)
There are different ways to design it, but a simple version could be a function that takes 2 operands and 1 result pointer as inputs, and returns boolean (true if success, false if it overflowed):
bool SafeAddIntInt(int32_t x, int32_t y, int32_t *r);
so the caller could say int32_t result;
if (SafeAddIntInt(x, y, &result)) {
// do something with result
} else {
// handle overflow
}
An even simpler version could just abort on over/underflow.
Re:Git Security Vulnerabilities Announced
by tsimionescu on Tuesday January 17, 2023 @06:35PM
(#34421078)
Note that there is no such thing as integer underflow. INT_MIN-1 is an overflow just as much as INT_MAX+1.
Only floats can suffer from underflow, which happens when you want to represent a number whose absolute value is smaller than the floating point precision can allow (e.g. trying to represent 1/2^32 in a 32-bit float).