From owner-svn-src-stable-10@freebsd.org Thu Sep 8 07:14:49 2016 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A0A3EBD1777; Thu, 8 Sep 2016 07:14:49 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 72FCE25A; Thu, 8 Sep 2016 07:14:49 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u887EmQD007918; Thu, 8 Sep 2016 07:14:48 GMT (envelope-from ache@FreeBSD.org) Received: (from ache@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u887Ems0007917; Thu, 8 Sep 2016 07:14:48 GMT (envelope-from ache@FreeBSD.org) Message-Id: <201609080714.u887Ems0007917@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ache set sender to ache@FreeBSD.org using -f From: "Andrey A. Chernov" Date: Thu, 8 Sep 2016 07:14:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r305583 - stable/10/lib/libc/stdio X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Sep 2016 07:14:49 -0000 Author: ache Date: Thu Sep 8 07:14:48 2016 New Revision: 305583 URL: https://svnweb.freebsd.org/changeset/base/305583 Log: MFC r305413 Fix error handling. Modified: stable/10/lib/libc/stdio/fgets.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/stdio/fgets.c ============================================================================== --- stable/10/lib/libc/stdio/fgets.c Thu Sep 8 06:53:18 2016 (r305582) +++ stable/10/lib/libc/stdio/fgets.c Thu Sep 8 07:14:48 2016 (r305583) @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)fgets.c 8.2 __FBSDID("$FreeBSD$"); #include "namespace.h" +#include #include #include #include "un-namespace.h" @@ -55,11 +56,16 @@ fgets(char * __restrict buf, int n, FILE char *s; unsigned char *p, *t; - if (n <= 0) /* sanity check */ - return (NULL); - FLOCKFILE(fp); ORIENT(fp, -1); + + if (n <= 0) { /* sanity check */ + fp->_flags |= __SERR; + errno = EINVAL; + FUNLOCKFILE(fp); + return (NULL); + } + s = buf; n--; /* leave space for NUL */ while (n != 0) { @@ -69,7 +75,7 @@ fgets(char * __restrict buf, int n, FILE if ((len = fp->_r) <= 0) { if (__srefill(fp)) { /* EOF/error: stop with partial or no line */ - if (s == buf) { + if (!__sfeof(fp) || s == buf) { FUNLOCKFILE(fp); return (NULL); }