target-cris/translate.c: fix out of bounds read

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>
This commit is contained in:
zhanghailiang 2014-11-17 13:57:34 +08:00 committed by Paolo Bonzini
parent 0e8b439ae5
commit fae38221e7

View File

@ -169,9 +169,7 @@ static int preg_sizes[] = {
static inline void t_gen_mov_TN_preg(TCGv tn, int r) static inline void t_gen_mov_TN_preg(TCGv tn, int r)
{ {
if (r < 0 || r > 15) { assert(r >= 0 && r <= 15);
fprintf(stderr, "wrong register read $p%d\n", r);
}
if (r == PR_BZ || r == PR_WZ || r == PR_DZ) { if (r == PR_BZ || r == PR_WZ || r == PR_DZ) {
tcg_gen_mov_tl(tn, tcg_const_tl(0)); tcg_gen_mov_tl(tn, tcg_const_tl(0));
} else if (r == PR_VR) { } 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) static inline void t_gen_mov_preg_TN(DisasContext *dc, int r, TCGv tn)
{ {
if (r < 0 || r > 15) { assert(r >= 0 && r <= 15);
fprintf(stderr, "wrong register write $p%d\n", r);
}
if (r == PR_BZ || r == PR_WZ || r == PR_DZ) { if (r == PR_BZ || r == PR_WZ || r == PR_DZ) {
return; return;
} else if (r == PR_SRS) { } else if (r == PR_SRS) {