diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2009-06-02 22:28:19 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2009-06-02 22:28:19 +0000 |
commit | 6f562a44b936777ea90d751a103db83f035052f0 (patch) | |
tree | 0c59a73bf81b4171f2e6167ce05ee0ea70ce29ce /lib/libc/stdio/fgets.c | |
parent | dcf4d397824201f96011cdae0bf8db8860a85df8 (diff) |
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.c | 7 |
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; |