* [Qemu-devel] [PATCH] lm4549: Fix buffer overflow
@ 2012-09-01 10:43 Stefan Weil
2012-09-01 11:42 ` Peter Maydell
2012-09-22 15:36 ` Stefan Hajnoczi
0 siblings, 2 replies; 3+ messages in thread
From: Stefan Weil @ 2012-09-01 10:43 UTC (permalink / raw)
To: Mathieu Sonet; +Cc: qemu-trivial, Stefan Weil, qemu-devel
Report from smatch:
lm4549.c:234 lm4549_write_samples(14) error:
buffer overflow 's->buffer' 1024 <= 1024
There must be enough space to add two entries starting with index
s->buffer_level, therefore the old check was wrong.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
hw/lm4549.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/lm4549.c b/hw/lm4549.c
index 80b3ec4..e0137d5 100644
--- a/hw/lm4549.c
+++ b/hw/lm4549.c
@@ -224,7 +224,7 @@ uint32_t lm4549_write_samples(lm4549_state *s, uint32_t left, uint32_t right)
This model supports 16-bit playback.
*/
- if (s->buffer_level >= LM4549_BUFFER_SIZE) {
+ if (s->buffer_level > LM4549_BUFFER_SIZE - 2) {
DPRINTF("write_sample Buffer full\n");
return 0;
}
--
1.7.10
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] lm4549: Fix buffer overflow
2012-09-01 10:43 [Qemu-devel] [PATCH] lm4549: Fix buffer overflow Stefan Weil
@ 2012-09-01 11:42 ` Peter Maydell
2012-09-22 15:36 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2012-09-01 11:42 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-trivial, qemu-devel, Mathieu Sonet
On 1 September 2012 11:43, Stefan Weil <sw@weilnetz.de> wrote:
> Report from smatch:
> lm4549.c:234 lm4549_write_samples(14) error:
> buffer overflow 's->buffer' 1024 <= 1024
>
> There must be enough space to add two entries starting with index
> s->buffer_level, therefore the old check was wrong.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
> hw/lm4549.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/lm4549.c b/hw/lm4549.c
> index 80b3ec4..e0137d5 100644
> --- a/hw/lm4549.c
> +++ b/hw/lm4549.c
> @@ -224,7 +224,7 @@ uint32_t lm4549_write_samples(lm4549_state *s, uint32_t left, uint32_t right)
> This model supports 16-bit playback.
> */
>
> - if (s->buffer_level >= LM4549_BUFFER_SIZE) {
> + if (s->buffer_level > LM4549_BUFFER_SIZE - 2) {
> DPRINTF("write_sample Buffer full\n");
> return 0;
> }
> --
> 1.7.10
I don't object to making the change to placate the analyser,
but I don't think this is actually a buffer overrun. We always
add and remove samples from the buffer two at a time, so it's
not possible to get here with s->buffer_level == BUFFER_SIZE-1
(which is the only case where the old and new conditions
give different answers).
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] lm4549: Fix buffer overflow
2012-09-01 10:43 [Qemu-devel] [PATCH] lm4549: Fix buffer overflow Stefan Weil
2012-09-01 11:42 ` Peter Maydell
@ 2012-09-22 15:36 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2012-09-22 15:36 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-trivial, qemu-devel, Mathieu Sonet
On Sat, Sep 01, 2012 at 12:43:41PM +0200, Stefan Weil wrote:
> Report from smatch:
> lm4549.c:234 lm4549_write_samples(14) error:
> buffer overflow 's->buffer' 1024 <= 1024
>
> There must be enough space to add two entries starting with index
> s->buffer_level, therefore the old check was wrong.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
> hw/lm4549.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches
I've added Peter's comment to the commit message that the overflow
condition doesn't actually happen since we advance by two at a time.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-22 15:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-01 10:43 [Qemu-devel] [PATCH] lm4549: Fix buffer overflow Stefan Weil
2012-09-01 11:42 ` Peter Maydell
2012-09-22 15:36 ` Stefan Hajnoczi
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).