From: Oliver Kurth Date: Wed, 7 Feb 2018 00:32:39 +0000 (-0800) Subject: Fix memory corruption bug in StdIO_ReadNextLine X-Git-Tag: stable-10.3.0~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ccc073a58e1822dc4eb8c20e10dc89791643e9c;p=thirdparty%2Fopen-vm-tools.git Fix memory corruption bug in StdIO_ReadNextLine --- diff --git a/open-vm-tools/lib/misc/vmstdio.c b/open-vm-tools/lib/misc/vmstdio.c index 8b90e1e7b..8c447130d 100644 --- a/open-vm-tools/lib/misc/vmstdio.c +++ b/open-vm-tools/lib/misc/vmstdio.c @@ -217,11 +217,6 @@ StdIO_ReadNextLine(FILE *stream, // IN: data = DynBuf_Get(&b); size = DynBuf_GetSize(&b); - if (maxBufLength != 0 && size > maxBufLength) { - errno = E2BIG; - goto error; - } - max = DynBuf_GetAllocatedSize(&b); nr = max - size; @@ -232,6 +227,11 @@ StdIO_ReadNextLine(FILE *stream, // IN: size += nr; DynBuf_SetSize(&b, size); + if (maxBufLength != 0 && size > maxBufLength) { + errno = E2BIG; + goto error; + } + if (size < max) { /* SuperFgets() found end-of-line */