summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/sample-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-05-23 16:59:03 +0000
committerLennart Poettering <lennart@poettering.net>2007-05-23 16:59:03 +0000
commit33304ba1181bde267c8a54f6587778fe0cfd28b6 (patch)
treedcf9699621e9084c76297e6a4b0c9db5f1f3b886 /src/pulsecore/sample-util.c
parent4a05bc9bdcb4404f3e23cef367ff378b9e39d220 (diff)
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
Diffstat (limited to 'src/pulsecore/sample-util.c')
-rw-r--r--src/pulsecore/sample-util.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c
index 411787af..c8e7acf0 100644
--- a/src/pulsecore/sample-util.c
+++ b/src/pulsecore/sample-util.c
@@ -38,13 +38,25 @@
#include "sample-util.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) {
+ size_t fs;
assert(pool);
assert(spec);
if (length == 0)
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);
}