From ab05a79c21df9d69acdbf5bed9fc122ac5a92bc8 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Fri, 23 Oct 2015 18:06:17 +0200 Subject: [PATCH] winpr/stream: don't allow 0-size streams --- winpr/libwinpr/utils/stream.c | 3 +++ winpr/libwinpr/utils/test/TestStream.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/winpr/libwinpr/utils/stream.c b/winpr/libwinpr/utils/stream.c index b0d864bce..31d4493f2 100644 --- a/winpr/libwinpr/utils/stream.c +++ b/winpr/libwinpr/utils/stream.c @@ -70,6 +70,9 @@ wStream* Stream_New(BYTE* buffer, size_t size) { wStream* s; + if (!buffer && !size) + return NULL; + s = malloc(sizeof(wStream)); if (!s) diff --git a/winpr/libwinpr/utils/test/TestStream.c b/winpr/libwinpr/utils/test/TestStream.c index 96fb4fea8..005dcef1b 100644 --- a/winpr/libwinpr/utils/test/TestStream.c +++ b/winpr/libwinpr/utils/test/TestStream.c @@ -65,6 +65,16 @@ static BOOL TestStream_Verify(wStream* s, int mincap, int len, int pos) return TRUE; } +static BOOL TestStream_New() +{ + wStream *s = NULL; + /* Test creation of a 0-size stream with no buffer */ + s = Stream_New(NULL, 0); + if (s) + return FALSE; + return TRUE; +} + static BOOL TestStream_Create(int count, BOOL selfAlloc) { @@ -266,6 +276,8 @@ int TestStream(int argc, char* argv[]) if (!TestStream_Reading()) return 4; + if (!TestStream_New()) + return 5; /** * FIXME: Add tests for * Stream_Write_*