[uclibc-ng-devel] Fix NULL pointer dereference in open_memstream()
diff mbox series

Message ID CAPmKWpG+tiYAu6gP177E8FiTYGXe0dSdd6ahfzx0pfEqLOSTaA@mail.gmail.com
State Accepted
Headers show
Series
  • [uclibc-ng-devel] Fix NULL pointer dereference in open_memstream()
Related show

Commit Message

Eugene Yudin Feb. 22, 2019, 4:47 p.m. UTC
Hi,

Current version of uClibc-ng has issue in open_memstream() function.
If the cookie variable is NULL (due malloc() fail) then null pointer is
dereferenced after if block.

The attached patch fixes this issue.

Patch
diff mbox series

diff --git a/libc/stdio/open_memstream.c b/libc/stdio/open_memstream.c
index 17ef191cb..71a84138d 100644
--- a/libc/stdio/open_memstream.c
+++ b/libc/stdio/open_memstream.c
@@ -156,9 +156,10 @@  FILE *open_memstream(char **bufloc, size_t *sizeloc)
 			__STDIO_STREAM_VALIDATE(fp);
 			return fp;
 		}
+
+		free(cookie->buf);
 	}
 
-	free(cookie->buf);
  EXIT_cookie:
 	free(cookie);