Skip to content

Commit 4c56eb6

Browse files
tagunilfabiobaltieri
authored andcommitted
posix: clock: fix potential int32_t overflow in __z_clock_nanosleep
As k_sleep returns int32_t, there is a possibility for integer overflow during conversion from milliseconds to nanoseconds. Signed-off-by: Ilya Tagunov <[email protected]>
1 parent bf52585 commit 4c56eb6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/posix/options/clock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static int __z_clock_nanosleep(clockid_t clock_id, int flags, const struct times
220220
unlikely(rqtp->tv_sec >= ULLONG_MAX / NSEC_PER_SEC)) {
221221

222222
ns = rqtp->tv_nsec + NSEC_PER_SEC
223-
+ k_sleep(K_SECONDS(rqtp->tv_sec - 1)) * NSEC_PER_MSEC;
223+
+ (uint64_t)k_sleep(K_SECONDS(rqtp->tv_sec - 1)) * NSEC_PER_MSEC;
224224
} else {
225225
ns = (uint64_t)rqtp->tv_sec * NSEC_PER_SEC + rqtp->tv_nsec;
226226
}

0 commit comments

Comments
 (0)