From owner-svn-src-head@freebsd.org Mon May 15 17:57:10 2017 Return-Path: Delivered-To: svn-src-head@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 AA696D6E916; Mon, 15 May 2017 17:57:10 +0000 (UTC) (envelope-from emaste@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 79D7D3DC; Mon, 15 May 2017 17:57:10 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4FHv9Kk045922; Mon, 15 May 2017 17:57:09 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4FHv9Fk045921; Mon, 15 May 2017 17:57:09 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201705151757.v4FHv9Fk045921@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Mon, 15 May 2017 17:57:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318304 - head/lib/libc/gen X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 May 2017 17:57:10 -0000 Author: emaste Date: Mon May 15 17:57:09 2017 New Revision: 318304 URL: https://svnweb.freebsd.org/changeset/base/318304 Log: getusershell: don't write past end of line buffer reading local shells _local_initshells did not reset cp to the beginning of the line buffer for every iteration that it called fgets(3), leading to writing past the end of line with fairly long /etc/shells or excessively long line lengths. Correct this by properly resetting cp. PR: 192528 Submitted by: Kyle Evans Reviewed by: cem, jilles Differential Revision: https://reviews.freebsd.org/D10690 Modified: head/lib/libc/gen/getusershell.c Modified: head/lib/libc/gen/getusershell.c ============================================================================== --- head/lib/libc/gen/getusershell.c Mon May 15 17:54:36 2017 (r318303) +++ head/lib/libc/gen/getusershell.c Mon May 15 17:57:09 2017 (r318304) @@ -115,8 +115,8 @@ _local_initshells(void *rv, void *cb_dat if ((fp = fopen(_PATH_SHELLS, "re")) == NULL) return NS_UNAVAIL; - cp = line; - while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) { + while (fgets(line, MAXPATHLEN + 1, fp) != NULL) { + cp = line; while (*cp != '#' && *cp != '/' && *cp != '\0') cp++; if (*cp == '#' || *cp == '\0') @@ -124,7 +124,7 @@ _local_initshells(void *rv, void *cb_dat sp = cp; while (!isspace(*cp) && *cp != '#' && *cp != '\0') cp++; - *cp++ = '\0'; + *cp = '\0'; sl_add(sl, strdup(sp)); } (void)fclose(fp);