]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
vnc-enc-tight: Fix divide-by-zero in tight_detect_smooth_image{16,24,32}
authorGonglei <arei.gonglei@huawei.com>
Wed, 28 May 2014 13:21:35 +0000 (21:21 +0800)
committerGerd Hoffmann <kraxel@redhat.com>
Mon, 2 Jun 2014 14:30:52 +0000 (16:30 +0200)
Spotted by Coverity:

(1) Event assignment:  Assigning: "pixels" = "0".
(2) Event cond_true:  Condition "y < h", taking true branch
(3) Event cond_false:  Condition "x < w", taking false branch
(4) Event loop_end:  Reached end of loop
(5) Event divide_by_zero:  In expression "(stats[0] + stats[1]) * 100U / pixels",
division by expression "pixels" which may be zero has undefined behavior.

290     DEFINE_DETECT_FUNCTION(16)
291     DEFINE_DETECT_FUNCTION(32)

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
ui/vnc-enc-tight.c

index 59b59c0c79c63e8783dae0740a49f8ac2c2d9524..f02352cc466b5acf65f06318022f328ac3d2a018 100644 (file)
@@ -181,6 +181,10 @@ tight_detect_smooth_image24(VncState *vs, int w, int h)
         }
     }
 
+    if (pixels == 0) {
+        return 0;
+    }
+
     /* 95% smooth or more ... */
     if (stats[0] * 33 / pixels >= 95) {
         return 0;
@@ -267,7 +271,9 @@ tight_detect_smooth_image24(VncState *vs, int w, int h)
                 y += w;                                                 \
             }                                                           \
         }                                                               \
-                                                                        \
+        if (pixels == 0) {                                              \
+            return 0;                                                   \
+        }                                                               \
         if ((stats[0] + stats[1]) * 100 / pixels >= 90) {               \
             return 0;                                                   \
         }                                                               \