From 6f562a44b936777ea90d751a103db83f035052f0 Mon Sep 17 00:00:00 2001 From: Ray Lai Date: Tue, 2 Jun 2009 22:28:19 +0000 Subject: Set errno to EINVAL when fgets is given a non-positive size. OK millert otto --- lib/libc/stdio/fgets.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/libc/stdio/fgets.c') 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 #include #include #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; -- cgit v1.2.3