winpr/stream: don't allow 0-size streams
authorBernhard Miklautz <bernhard.miklautz@thincast.com>
Fri, 23 Oct 2015 16:06:17 +0000 (18:06 +0200)
committerBernhard Miklautz <bernhard.miklautz@thincast.com>
Fri, 23 Oct 2015 16:38:41 +0000 (18:38 +0200)
winpr/libwinpr/utils/stream.c
winpr/libwinpr/utils/test/TestStream.c

index b0d864b..31d4493 100644 (file)
@@ -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)
index 96fb4fe..005dcef 100644 (file)
@@ -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_*