Skip to content

Commit

Permalink
Fix #1458, Adds integer overflow protection to osapi-clock multiplica…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
jdfiguer authored and jdfiguer committed Jun 18, 2024
1 parent 6483329 commit 0ab1fb3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/os/inc/osapi-clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,17 @@ static inline int64 OS_TimeGetTotalMicroseconds(OS_time_t tm)
*/
static inline OS_time_t OS_TimeFromTotalMicroseconds(int64 tm)
{
OS_time_t ostm = {tm * OS_TIME_TICKS_PER_USEC};
OS_time_t ostm;

// Check for overflow before performing multiplication
if (tm > INT64_MAX / OS_TIME_TICKS_PER_USEC) {
// If multiplication would overflow
ostm.ticks = INT64_MAX; // Using INT64_MAX to indicate overflow
} else {
// Perform multiplication if it is safe
ostm.ticks = tm * OS_TIME_TICKS_PER_USEC;
}

return ostm;
}

Expand Down

0 comments on commit 0ab1fb3

Please sign in to comment.