From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gonglei <arei.gonglei@huawei.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PULL 3/3] vnc-enc-tight: Fix divide-by-zero in tight_detect_smooth_image{16, 24, 32}
Date: Mon, 2 Jun 2014 16:33:12 +0200 [thread overview]
Message-ID: <1401719592-26362-4-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1401719592-26362-1-git-send-email-kraxel@redhat.com>
From: Gonglei <arei.gonglei@huawei.com>
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 | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index 59b59c0..f02352c 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -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; \
} \
--
1.8.3.1
next prev parent reply other threads:[~2014-06-02 14:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-02 14:33 [Qemu-devel] [PULL 0/3] vnc patch queue Gerd Hoffmann
2014-06-02 14:33 ` [Qemu-devel] [PULL 1/3] vnc: refuse to set a password with VNC_AUTH_NONE Gerd Hoffmann
2014-06-02 14:33 ` [Qemu-devel] [PULL 2/3] vnc: add trace events for key events Gerd Hoffmann
2014-06-02 14:33 ` Gerd Hoffmann [this message]
2014-06-02 15:09 ` [Qemu-devel] [PULL 0/3] vnc patch queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1401719592-26362-4-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=aliguori@amazon.com \
--cc=arei.gonglei@huawei.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).