[Spice-devel] [PATCH] prevent integer overflow on 32 bit

Frediano Ziglio fziglio at redhat.com
Fri Aug 21 02:23:57 PDT 2015


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 at redhat.com>
---
 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



More information about the Spice-devel mailing list