Fix a DoS with allocating overly large silence buffers. (Identified by Luigi Auriemma (re #67)

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1450 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2007-05-23 16:59:03 +00:00
parent 4a05bc9bdc
commit 33304ba118

View file

@ -38,13 +38,25 @@
#include "sample-util.h" #include "sample-util.h"
#include "endianmacros.h" #include "endianmacros.h"
#define PA_SILENCE_MAX (1024*1024*1)
pa_memblock *pa_silence_memblock_new(pa_mempool *pool, const pa_sample_spec *spec, size_t length) { pa_memblock *pa_silence_memblock_new(pa_mempool *pool, const pa_sample_spec *spec, size_t length) {
size_t fs;
assert(pool); assert(pool);
assert(spec); assert(spec);
if (length == 0) if (length == 0)
length = pa_bytes_per_second(spec)/20; /* 50 ms */ length = pa_bytes_per_second(spec)/20; /* 50 ms */
if (length > PA_SILENCE_MAX)
length = PA_SILENCE_MAX;
fs = pa_frame_size(spec);
length = ((PA_SILENCE_MAX+fs-1) / fs) * fs;
if (length <= 0)
length = fs;
return pa_silence_memblock(pa_memblock_new(pool, length), spec); return pa_silence_memblock(pa_memblock_new(pool, length), spec);
} }