summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2009-06-02 22:28:19 +0000
committerRay Lai <ray@cvs.openbsd.org>2009-06-02 22:28:19 +0000
commit6f562a44b936777ea90d751a103db83f035052f0 (patch)
tree0c59a73bf81b4171f2e6167ce05ee0ea70ce29ce
parentdcf4d397824201f96011cdae0bf8db8860a85df8 (diff)
Set errno to EINVAL when fgets is given a non-positive size.
OK millert otto
-rw-r--r--lib/libc/stdio/fgets.38
-rw-r--r--lib/libc/stdio/fgets.c7
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/libc/stdio/fgets.3 b/lib/libc/stdio/fgets.3
index d459f35958f..13b213088ef 100644
--- a/lib/libc/stdio/fgets.3
+++ b/lib/libc/stdio/fgets.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: fgets.3,v 1.28 2007/09/07 05:17:59 cloder Exp $
+.\" $OpenBSD: fgets.3,v 1.29 2009/06/02 22:28:18 ray Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -31,7 +31,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: September 7 2007 $
+.Dd $Mdocdate: June 2 2009 $
.Dt FGETS 3
.Os
.Sh NAME
@@ -114,6 +114,10 @@ is 1.
The given
.Fa stream
is not a readable stream.
+.It Bq Er EINVAL
+The given
+.Fa size
+is less than or equal to 0.
.El
.Pp
The function
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;