Skip to content

Commit 32b8fe7

Browse files
committed
fix NULL dereference in fgetc/fputc when stream is NULL
1 parent b2a1f5e commit 32b8fe7

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/libc/fgetc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ int __attribute__((weak)) fgetc(FILE *stream)
55
{
66
int c;
77

8-
if (stream == NULL ||
9-
stream == stdout ||
10-
stream == stderr)
8+
if (stream == NULL)
9+
{
10+
return EOF;
11+
}
12+
13+
if (stream == stdout || stream == stderr)
1114
{
1215
c = EOF;
1316
}

src/libc/fputc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ int __attribute__((weak)) fputc(int c, FILE *stream)
55
{
66
int ret;
77

8-
if (stream == NULL || stream == stdin)
8+
if (stream == NULL)
9+
{
10+
return EOF;
11+
}
12+
13+
if (stream == stdin)
914
{
1015
ret = EOF;
1116
}

0 commit comments

Comments
 (0)