qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: zhanghailiang <zhang.zhanghailiang@huawei.com>, qemu-trivial@nongnu.org
Cc: edgar.iglesias@gmail.com, qemu-devel@nongnu.org,
	peter.huangpeng@huawei.com
Subject: Re: [Qemu-devel] [PATCH] target-cris/translate.c: fix out of bounds read
Date: Mon, 17 Nov 2014 11:59:38 +0100	[thread overview]
Message-ID: <5469D51A.9010703@redhat.com> (raw)
In-Reply-To: <1416203854-11908-1-git-send-email-zhang.zhanghailiang@huawei.com>

On 17/11/2014 06:57, zhanghailiang wrote:
> 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>
> ---
>  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) {
> 

Applied, thanks.

Paolo

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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-17  5:57 [Qemu-devel] [PATCH] target-cris/translate.c: fix out of bounds read zhanghailiang
2014-11-17 10:59 ` Paolo Bonzini [this message]

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=5469D51A.9010703@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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).