[PATCH] prevent integer overflow on 32 bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 32 bit machine timespec->tv_sec (time_t) is 32 bit.
Also 1000 * 1000 * 1000 is 32 bit.
The multiplication 32 x 32 lead to a 32 bit however this can overflow.
Convert the first factor to 64 bit before multiply solve the issue.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/red_worker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/red_worker.c b/server/red_worker.c
index 1655bbe..d4abc3c 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -163,7 +163,7 @@ static void rendering_incorrect(const char *msg)
 
 static inline red_time_t timespec_to_red_time(struct timespec *time)
 {
-    return time->tv_sec * (1000 * 1000 * 1000) + time->tv_nsec;
+    return (red_time_t) time->tv_sec * (1000 * 1000 * 1000) + time->tv_nsec;
 }
 
 #if defined(RED_WORKER_STAT) || defined(COMPRESS_STAT)
-- 
2.4.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]