9
0
Fork 0

libc: stdio: Fix NULL pointer dereference in ungetc(). If 'stream' was NULL, 'stream->fs_oflags' was evaluated. From Juha Niskanen

This commit is contained in:
Gregory Nutt 2015-03-12 07:51:23 -06:00
parent 9ff6f20b49
commit 10b63b1bd5
1 changed files with 9 additions and 2 deletions

View File

@ -94,10 +94,17 @@ int ungetc(int c, FAR FILE *stream)
int nungotten;
#endif
/* Verify that a non-NULL stream was provided */
if (!stream)
{
set_errno(EBADF);
return EOF;
}
/* Stream must be open for read access */
if ((stream && stream->fs_fd < 0) ||
((stream->fs_oflags & O_RDOK) == 0))
if ((stream->fs_fd < 0) || ((stream->fs_oflags & O_RDOK) == 0))
{
set_errno(EBADF);
return EOF;