From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqFKH-00025o-4E for qemu-devel@nongnu.org; Mon, 17 Nov 2014 00:58:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqFKC-00028y-51 for qemu-devel@nongnu.org; Mon, 17 Nov 2014 00:58:13 -0500 From: zhanghailiang Date: Mon, 17 Nov 2014 13:57:34 +0800 Message-ID: <1416203854-11908-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH] target-cris/translate.c: fix out of bounds read List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-trivial@nongnu.org Cc: zhanghailiang , edgar.iglesias@gmail.com, peter.huangpeng@huawei.com, qemu-devel@nongnu.org, pbonzini@redhat.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 --- 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.7.12.4