diff options
| author | John Baldwin <jhb@FreeBSD.org> | 2008-02-27 19:02:02 +0000 |
|---|---|---|
| committer | John Baldwin <jhb@FreeBSD.org> | 2008-02-27 19:02:02 +0000 |
| commit | c55d7e868aeb0e29e47c3a8ea9238e143f2a4c78 (patch) | |
| tree | 636eaa9d47e5f42f8f59cf335161c68af6b7300a /lib/libc/stdio/fopen.c | |
| parent | ae87be447c2fb719e44536229cb72d5c1b9d8d31 (diff) | |
Notes
Diffstat (limited to 'lib/libc/stdio/fopen.c')
| -rw-r--r-- | lib/libc/stdio/fopen.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index 9cedcda6a4df..a6c0028dbd96 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <unistd.h> #include <stdio.h> #include <errno.h> #include "un-namespace.h" @@ -63,6 +64,18 @@ fopen(file, mode) fp->_flags = 0; /* release */ return (NULL); } + /* + * File descriptors are a full int, but _file is only a short. + * If we get a valid file descriptor that is greater than + * SHRT_MAX, then the fd will get sign-extended into an + * invalid file descriptor. Handle this case by failing the + * open. + */ + if (f > SHRT_MAX) { + _close(f); + errno = EMFILE; + return (NULL); + } fp->_file = f; fp->_flags = flags; fp->_cookie = fp; |
