diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-03-12 07:51:23 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-03-12 07:51:23 -0600 |
commit | 10b63b1bd54f1af2b88fab5e5bc6e8f15a6f1d88 (patch) | |
tree | 3c0fb18204e199393d84cbe7349237c158145779 /nuttx | |
parent | 9ff6f20b490ab10db5f64210ac96e2f44f776c94 (diff) | |
download | px4-nuttx-10b63b1bd54f1af2b88fab5e5bc6e8f15a6f1d88.tar.gz px4-nuttx-10b63b1bd54f1af2b88fab5e5bc6e8f15a6f1d88.tar.bz2 px4-nuttx-10b63b1bd54f1af2b88fab5e5bc6e8f15a6f1d88.zip |
libc: stdio: Fix NULL pointer dereference in ungetc(). If 'stream' was NULL, 'stream->fs_oflags' was evaluated. From Juha Niskanen
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/libc/stdio/lib_ungetc.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/nuttx/libc/stdio/lib_ungetc.c b/nuttx/libc/stdio/lib_ungetc.c index 9d14499d7..bf8699a38 100644 --- a/nuttx/libc/stdio/lib_ungetc.c +++ b/nuttx/libc/stdio/lib_ungetc.c @@ -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; |