From a34e023a33034819043fde25662126fb3edfbd17 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 9 Dec 2020 21:12:40 +0100 Subject: LibC: Make getdelim() fail with EINVAL on null input pointers This matches some other libc's. --- Libraries/LibC/stdio.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Libraries/LibC/stdio.cpp b/Libraries/LibC/stdio.cpp index a281498004..f39a7f0639 100644 --- a/Libraries/LibC/stdio.cpp +++ b/Libraries/LibC/stdio.cpp @@ -663,7 +663,11 @@ int getchar() ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream) { - char *ptr, *eptr; + if (!lineptr || !n) { + errno = EINVAL; + return -1; + } + if (*lineptr == nullptr || *n == 0) { *n = BUFSIZ; if ((*lineptr = static_cast(malloc(*n))) == nullptr) { @@ -671,6 +675,8 @@ ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream) } } + char* ptr; + char* eptr; for (ptr = *lineptr, eptr = *lineptr + *n;;) { int c = fgetc(stream); if (c == -1) { -- cgit v1.2.3