Skip to contentSkip to conversation

target-cris: Fix buffer overflow

PATCH Superseded Stefan Weil 2 participants 3 messages Sep 4, 2012 – Sep 7, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-cris: Fix buffer overflow

Report from smatch:

target-cris/translate.c:3464 cpu_dump_state(32) error:
buffer overflow 'env->sregs' 4 <= 255

sregs is declared 'uint32_t sregs[4][16]', so the first index must be less than 4.

---

I did not fix tabs, therefore checkpatch.pl reports an error.

 target-cris/translate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-cris/translate.c +1 -1
index 1ad9ec7..34c0452 100644
@@ -3458,7 +3458,7 @@ void cpu_dump_state (CPUCRISState *env, FILE *f, fprintf_function cpu_fprintf,
 	}
 	srs = env->pregs[PR_SRS];
 	cpu_fprintf(f, "\nsupport function regs bank %x:\n", srs);
-	if (srs < 256) {
+	if (srs < 4) {
 		for (i = 0; i < 16; i++) {
 			cpu_fprintf(f, "s%2.2d=%8.8x ",
 				    i, env->sregs[srs][i]);
Signature · 1 line
1.7.10
#1 lore raw

Thanks Stefan. Ill apply this when i get back to swe in a couple of days.

Cheers

---
Sent from my phone

Quoted 34 lines · Stefan Weil

Report from smatch:

target-cris/translate.c:3464 cpu_dump_state(32) error:
buffer overflow 'env->sregs' 4 <= 255

sregs is declared 'uint32_t sregs[4][16]', so the first index must be less than 4.

---

I did not fix tabs, therefore checkpatch.pl reports an error.

 target-cris/translate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-cris/translate.c +1 -1
index 1ad9ec7..34c0452 100644
@@ -3458,7 +3458,7 @@ void cpu_dump_state (CPUCRISState *env, FILE *f,
 fprintf_function cpu_fprintf,
        }
        srs = env->pregs[PR_SRS];
        cpu_fprintf(f, "\nsupport function regs bank %x:\n", srs);
-       if (srs < 256) {
+       if (srs < 4) {
                for (i = 0; i < 16; i++) {
                        cpu_fprintf(f, "s%2.2d=%8.8x ",
                                    i, env->sregs[srs][i]);

--
1.7.10

#2 lore raw
In reply to Stefan Weil
Quoted 7 lines · Stefan Weil

Report from smatch:

target-cris/translate.c:3464 cpu_dump_state(32) error:
buffer overflow 'env->sregs' 4 <= 255

sregs is declared 'uint32_t sregs[4][16]', so the first index must be less than 4.

Hi Stefan,

I think it would be better to use ARRAY_SIZE(env->sregs) instead of 4.

The cris arch allows up to 256 sregs, but we only implement 4 at the moment. There are other uses of hardcoded 4 in the code that could be fixed aswell if you have time.

Thanks,
Edgar