qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: [Qemu-devel] [PULL 11/12] target-cris/translate.c: fix out of bounds read
Date: Mon, 17 Nov 2014 18:08:18 +0100	[thread overview]
Message-ID: <1416244099-7217-12-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1416244099-7217-1-git-send-email-pbonzini@redhat.com>

From: zhanghailiang <zhang.zhanghailiang@huawei.com>

In function t_gen_mov_TN_preg and t_gen_mov_preg_TN, The begin check about the
validity of in-parameter 'r' is useless. We still access cpu_PR[r] in the
follow code if it is invalid. Which will be an out-of-bounds read error.

Fix it by using assert() to ensure it is valid before using it.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target-cris/translate.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/target-cris/translate.c b/target-cris/translate.c
index e37b04e..76406af 100644
--- a/target-cris/translate.c
+++ b/target-cris/translate.c
@@ -169,9 +169,7 @@ static int preg_sizes[] = {
 
 static inline void t_gen_mov_TN_preg(TCGv tn, int r)
 {
-    if (r < 0 || r > 15) {
-        fprintf(stderr, "wrong register read $p%d\n", r);
-    }
+    assert(r >= 0 && r <= 15);
     if (r == PR_BZ || r == PR_WZ || r == PR_DZ) {
         tcg_gen_mov_tl(tn, tcg_const_tl(0));
     } else if (r == PR_VR) {
@@ -182,9 +180,7 @@ static inline void t_gen_mov_TN_preg(TCGv tn, int r)
 }
 static inline void t_gen_mov_preg_TN(DisasContext *dc, int r, TCGv tn)
 {
-    if (r < 0 || r > 15) {
-        fprintf(stderr, "wrong register write $p%d\n", r);
-    }
+    assert(r >= 0 && r <= 15);
     if (r == PR_BZ || r == PR_WZ || r == PR_DZ) {
         return;
     } else if (r == PR_SRS) {
-- 
1.8.3.1

  parent reply	other threads:[~2014-11-17 17:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-17 17:08 [Qemu-devel] [PULL 00/12] Coverity fixes for 2.2.0-rc2 Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 01/12] libcacard: fix resource leak Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 02/12] l2tpv3: fix possible double free Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 03/12] l2tpv3: fix fd leak Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 04/12] mips_mipssim: fix use-after-free for filename Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 05/12] qga: fix false negative argument passing Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 06/12] loader: fix NEGATIVE_RETURNS Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 07/12] nvme: remove superfluous check Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 08/12] acl: fix memory leak Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 09/12] qemu-char: fix MISSING_COMMA Paolo Bonzini
2014-11-17 17:08 ` [Qemu-devel] [PULL 10/12] shpc: fix error propaagation Paolo Bonzini
2014-11-17 17:08 ` Paolo Bonzini [this message]
2014-11-17 17:08 ` [Qemu-devel] [PULL 12/12] hcd-musb: fix dereference null return value Paolo Bonzini
2014-11-17 19:29 ` [Qemu-devel] [PULL 00/12] Coverity fixes for 2.2.0-rc2 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=1416244099-7217-12-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhang.zhanghailiang@huawei.com \
    /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).