From: Benjamin Otte Date: Tue, 20 Jul 2004 15:33:52 +0000 (+0000) Subject: fix buffer overflows X-Git-Tag: v1.0.6~7 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=f3fff3e0ef130a9a2c8c773ca63d9b60a567f4f6;p=alsa-lib.git fix buffer overflows Signed-off-by: Benjamin Otte --- diff --git a/src/output.c b/src/output.c index 025d2f0c..2fbabed2 100644 --- a/src/output.c +++ b/src/output.c @@ -255,7 +255,9 @@ static int snd_output_buffer_need(snd_output_t *output, size_t size) if (buffer->alloc == 0) alloc = 256; else - alloc = buffer->alloc * 2; + alloc = buffer->alloc; + while (alloc < size) + alloc *= 2; buffer->buf = realloc(buffer->buf, alloc); if (!buffer->buf) return -ENOMEM; @@ -281,8 +283,9 @@ static int snd_output_buffer_print(snd_output_t *output, const char *format, va_ result = snd_output_buffer_need(output, size); if (result < 0) return result; - result = vsprintf(buffer->buf + buffer->size, format, args); + result = vsnprintf(buffer->buf + buffer->size, result, format, args); assert(result == (int)size); + buffer->size += result; return result; }