diff options
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/fdopen.c | 9 | ||||
-rw-r--r-- | lib/libc/stdio/fopen.c | 12 | ||||
-rw-r--r-- | lib/libc/stdio/freopen.c | 10 |
3 files changed, 28 insertions, 3 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); diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index b063e4545f8..64f81ea77ab 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fopen.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: fopen.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. @@ -34,6 +34,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <errno.h> #include "local.h" @@ -53,6 +54,15 @@ fopen(const char *file, const char *mode) fp->_flags = 0; /* release */ return (NULL); } + + /* _file is only a short */ + if (f > SHRT_MAX) { + fp->_flags = 0; /* release */ + close(f); + errno = EMFILE; + return (NULL); + } + fp->_file = f; fp->_flags = flags; fp->_cookie = fp; diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index 414d8108e63..cd2d833846b 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: freopen.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: freopen.c,v 1.10 2008/04/21 12:28:35 otto Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -35,6 +35,7 @@ #include <sys/stat.h> #include <fcntl.h> #include <errno.h> +#include <limits.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> @@ -136,6 +137,13 @@ freopen(const char *file, const char *mode, FILE *fp) } } + /* _file is only a short */ + if (f > SHRT_MAX) { + fp->_flags = 0; /* set it free */ + errno = EMFILE; + return (NULL); + } + fp->_flags = flags; fp->_file = f; fp->_cookie = fp; |