summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fgets.c
diff options
context:
space:
mode:
authorray <ray@openbsd.org>2009-06-02 22:28:18 +0000
committerray <ray@openbsd.org>2009-06-02 22:28:18 +0000
commitccb5c659f4bdd6e9732808c3c1549dd536d78de9 (patch)
tree8f631106c8e81c818b18553f874ceadcf52f0e17 /lib/libc/stdio/fgets.c
parentmake env->sc_listeners and env->sc_ssl pointers, one step further toward (diff)
downloadwireguard-openbsd-ccb5c659f4bdd6e9732808c3c1549dd536d78de9.tar.xz
wireguard-openbsd-ccb5c659f4bdd6e9732808c3c1549dd536d78de9.zip
Set errno to EINVAL when fgets is given a non-positive size.
OK millert otto
Diffstat (limited to 'lib/libc/stdio/fgets.c')
-rw-r--r--lib/libc/stdio/fgets.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c
index 92fdcf78ff5..536935256be 100644
--- a/lib/libc/stdio/fgets.c
+++ b/lib/libc/stdio/fgets.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fgets.c,v 1.10 2005/08/08 08:05:36 espie Exp $ */
+/* $OpenBSD: fgets.c,v 1.11 2009/06/02 22:28:18 ray Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,6 +31,7 @@
* SUCH DAMAGE.
*/
+#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "local.h"
@@ -48,8 +49,10 @@ fgets(char *buf, int n, FILE *fp)
char *s;
unsigned char *p, *t;
- if (n <= 0) /* sanity check */
+ if (n <= 0) { /* sanity check */
+ errno = EINVAL;
return (NULL);
+ }
_SET_ORIENTATION(fp, -1);
s = buf;