Fix potential overflow of lock_wait_timeout on 32-bit systems
General
Escalation
General
Escalation
Description
Background: In innobase_rename_table, the following code may cause an overflow:
long int lock_wait_timeout = thd_lock_wait_timeout(thd) * 4;
The maximum value of thd_lock_wait_timeout(thd) can be 1,073,741,824, but on 32-bit systems, long int has a range of -2,147,483,648 to 2,147,483,647. This could lead to an integer overflow when multiplying by 4. Fix Solutions: 1. Use a larger type (preferred):
long long lock_wait_timeout = static_cast<long long>(thd_lock_wait_timeout(thd)) * 4;
2.Add overflow check:
auto timeout = thd_lock_wait_timeout(thd);
if (timeout > (LONG_MAX / 4)) {
// Handle overflow (e.g., set to max or throw an error)
}
long int lock_wait_timeout = timeout * 4;
Background:
In
innobase_rename_table
, the following code may cause an overflow:long int lock_wait_timeout = thd_lock_wait_timeout(thd) * 4;
The maximum value of
thd_lock_wait_timeout(thd)
can be 1,073,741,824, but on 32-bit systems,long int
has a range of -2,147,483,648 to 2,147,483,647.This could lead to an integer overflow when multiplying by 4.
Fix Solutions:
1. Use a larger type (preferred):
long long lock_wait_timeout = static_cast<long long>(thd_lock_wait_timeout(thd)) * 4;
2.Add overflow check:
auto timeout = thd_lock_wait_timeout(thd); if (timeout > (LONG_MAX / 4)) { // Handle overflow (e.g., set to max or throw an error) } long int lock_wait_timeout = timeout * 4;