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_*