qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] target-cris: Fix buffer overflow
@ 2012-09-04  5:45 Stefan Weil
  2012-09-04 16:48 ` Edgar E. Iglesias
  2012-09-07  8:47 ` Edgar E. Iglesias
  0 siblings, 2 replies; 3+ messages in thread
From: Stefan Weil @ 2012-09-04  5:45 UTC (permalink / raw)
  To: Edgar E. Iglesias; +Cc: Stefan Weil, qemu-devel

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.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---

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

 target-cris/translate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target-cris/translate.c b/target-cris/translate.c
index 1ad9ec7..34c0452 100644
--- a/target-cris/translate.c
+++ b/target-cris/translate.c
@@ -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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] target-cris: Fix buffer overflow
  2012-09-04  5:45 [Qemu-devel] [PATCH] target-cris: Fix buffer overflow Stefan Weil
@ 2012-09-04 16:48 ` Edgar E. Iglesias
  2012-09-07  8:47 ` Edgar E. Iglesias
  1 sibling, 0 replies; 3+ messages in thread
From: Edgar E. Iglesias @ 2012-09-04 16:48 UTC (permalink / raw)
  To: Stefan Weil; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1209 bytes --]

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

Cheers

---
Sent from my phone
On Sep 3, 2012 10:46 PM, "Stefan Weil" <sw@weilnetz.de> wrote:

> 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.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>
> I did not fix tabs, therefore checkpatch.pl reports an error.
>
>  target-cris/translate.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target-cris/translate.c b/target-cris/translate.c
> index 1ad9ec7..34c0452 100644
> --- a/target-cris/translate.c
> +++ b/target-cris/translate.c
> @@ -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
>
>

[-- Attachment #2: Type: text/html, Size: 1709 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] target-cris: Fix buffer overflow
  2012-09-04  5:45 [Qemu-devel] [PATCH] target-cris: Fix buffer overflow Stefan Weil
  2012-09-04 16:48 ` Edgar E. Iglesias
@ 2012-09-07  8:47 ` Edgar E. Iglesias
  1 sibling, 0 replies; 3+ messages in thread
From: Edgar E. Iglesias @ 2012-09-07  8:47 UTC (permalink / raw)
  To: Stefan Weil; +Cc: qemu-devel

On Tue, Sep 04, 2012 at 07:45:52AM +0200, Stefan Weil wrote:
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-09-07  8:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-04  5:45 [Qemu-devel] [PATCH] target-cris: Fix buffer overflow Stefan Weil
2012-09-04 16:48 ` Edgar E. Iglesias
2012-09-07  8:47 ` Edgar E. Iglesias

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).