summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/freopen.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/freopen.c')
-rw-r--r--lib/libc/stdio/freopen.c10
1 files changed, 9 insertions, 1 deletions
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;