summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-09 21:12:40 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-09 21:12:40 +0100
commita34e023a33034819043fde25662126fb3edfbd17 (patch)
tree25513c5c8e747534fd9eb4eb096add52a7b90166 /Libraries
parent2981f10a5e43fa1e1217966d7a492a7c0e052b54 (diff)
downloadserenity-a34e023a33034819043fde25662126fb3edfbd17.zip
LibC: Make getdelim() fail with EINVAL on null input pointers
This matches some other libc's.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibC/stdio.cpp8
1 files changed, 7 insertions, 1 deletions
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<char*>(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) {