From owner-svn-src-stable@freebsd.org Mon Apr 24 22:37:55 2017 Return-Path: Delivered-To: svn-src-stable@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 65648D4E292; Mon, 24 Apr 2017 22:37:55 +0000 (UTC) (envelope-from brooks@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 34C951904; Mon, 24 Apr 2017 22:37:55 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3OMbsBL012051; Mon, 24 Apr 2017 22:37:54 GMT (envelope-from brooks@FreeBSD.org) Received: (from brooks@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3OMbsbC012050; Mon, 24 Apr 2017 22:37:54 GMT (envelope-from brooks@FreeBSD.org) Message-Id: <201704242237.v3OMbsbC012050@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: brooks set sender to brooks@FreeBSD.org using -f From: Brooks Davis Date: Mon, 24 Apr 2017 22:37:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r317391 - stable/11/lib/libc/gen X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Apr 2017 22:37:55 -0000 Author: brooks Date: Mon Apr 24 22:37:54 2017 New Revision: 317391 URL: https://svnweb.freebsd.org/changeset/base/317391 Log: MFC r316768: Fix an out-of-bounds write when a zero-length buffer is passed. Found with ttyname_test and CHERI bounds checking. Reviewed by: emaste Obtained from: CheriBSD Sponsored by: DARPA, AFRL Modified: stable/11/lib/libc/gen/ttyname.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libc/gen/ttyname.c ============================================================================== --- stable/11/lib/libc/gen/ttyname.c Mon Apr 24 22:35:00 2017 (r317390) +++ stable/11/lib/libc/gen/ttyname.c Mon Apr 24 22:37:54 2017 (r317391) @@ -61,6 +61,10 @@ ttyname_r(int fd, char *buf, size_t len) { size_t used; + /* Don't write off the end of a zero-length buffer. */ + if (len < 1) + return (ERANGE); + *buf = '\0'; /* Must be a terminal. */