diff options
author | 2008-04-21 12:28:35 +0000 | |
---|---|---|
committer | 2008-04-21 12:28:35 +0000 | |
commit | 67011cebfe037fa5d895ae9ae974133bc80d0783 (patch) | |
tree | 0652aaef628b760068754b61b79042f06c2dd619 /lib/libc/stdio/fdopen.c | |
parent | Initialize the correct variable in HUP handler if ed.hup in current (diff) | |
download | wireguard-openbsd-67011cebfe037fa5d895ae9ae974133bc80d0783.tar.xz wireguard-openbsd-67011cebfe037fa5d895ae9ae974133bc80d0783.zip |
_file is only a short, so prevent truncation if we happen to hit
upon a fd > SHRT_MAX. From freebsd via Jan Schaumann; ok deraadt@
millert@ espie@
Diffstat (limited to 'lib/libc/stdio/fdopen.c')
-rw-r--r-- | lib/libc/stdio/fdopen.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index 1df609c63c9..3e47f2c7426 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdopen.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: fdopen.c,v 1.6 2008/04/21 12:28:35 otto Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -33,6 +33,7 @@ #include <sys/types.h> #include <fcntl.h> +#include <limits.h> #include <unistd.h> #include <stdio.h> #include <errno.h> @@ -44,6 +45,12 @@ fdopen(int fd, const char *mode) FILE *fp; int flags, oflags, fdflags, tmp; + /* _file is only a short */ + if (fd > SHRT_MAX) { + errno = EMFILE; + return (NULL); + } + if ((flags = __sflags(mode, &oflags)) == 0) return (NULL); |