From owner-svn-src-stable@freebsd.org Sun Sep 13 13:58:47 2015 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 82DC7A02ADF; Sun, 13 Sep 2015 13:58:47 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::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 672FA1FC4; Sun, 13 Sep 2015 13:58:47 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8DDwlW0079413; Sun, 13 Sep 2015 13:58:47 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8DDwklq079410; Sun, 13 Sep 2015 13:58:46 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201509131358.t8DDwklq079410@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sun, 13 Sep 2015 13:58:46 +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: r287752 - in stable/10/bin/sh: . tests/builtins 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@freebsd.org X-Mailman-Version: 2.1.20 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: Sun, 13 Sep 2015 13:58:47 -0000 Author: jilles Date: Sun Sep 13 13:58:46 2015 New Revision: 287752 URL: https://svnweb.freebsd.org/changeset/base/287752 Log: MFC r287148: sh: Fix out of bounds read when there is no ] after a [:class:]. The initial check for a matching ] was incorrect if a ] may be consumed by a [:class:]. The subsequent loop assumed that there must be a ]. Remove the initial check and make the loop cope with a missing ]. Found with afl-fuzz. Added: stable/10/bin/sh/tests/builtins/case20.0 - copied unchanged from r287148, head/bin/sh/tests/builtins/case20.0 Modified: stable/10/bin/sh/expand.c stable/10/bin/sh/tests/builtins/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/bin/sh/expand.c ============================================================================== --- stable/10/bin/sh/expand.c Sun Sep 13 13:52:54 2015 (r287751) +++ stable/10/bin/sh/expand.c Sun Sep 13 13:58:46 2015 (r287752) @@ -1468,21 +1468,11 @@ patmatch(const char *pattern, const char bt_q = q; break; case '[': { - const char *endp; + const char *savep, *saveq; int invert, found; wchar_t chr; - endp = p; - if (*endp == '!' || *endp == '^') - endp++; - do { - while (*endp == CTLQUOTEMARK) - endp++; - if (*endp == 0) - goto dft; /* no matching ] */ - if (*endp == CTLESC) - endp++; - } while (*++endp != ']'); + savep = p, saveq = q; invert = 0; if (*p == '!' || *p == '^') { invert++; @@ -1501,6 +1491,11 @@ patmatch(const char *pattern, const char chr = (unsigned char)*q++; c = *p++; do { + if (c == '\0') { + p = savep, q = saveq; + c = '['; + goto dft; + } if (c == CTLQUOTEMARK) continue; if (c == '[' && *p == ':') { Modified: stable/10/bin/sh/tests/builtins/Makefile ============================================================================== --- stable/10/bin/sh/tests/builtins/Makefile Sun Sep 13 13:52:54 2015 (r287751) +++ stable/10/bin/sh/tests/builtins/Makefile Sun Sep 13 13:58:46 2015 (r287752) @@ -34,6 +34,7 @@ FILES+= case16.0 FILES+= case17.0 FILES+= case18.0 FILES+= case19.0 +FILES+= case20.0 FILES+= cd1.0 FILES+= cd2.0 FILES+= cd3.0 Copied: stable/10/bin/sh/tests/builtins/case20.0 (from r287148, head/bin/sh/tests/builtins/case20.0) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/bin/sh/tests/builtins/case20.0 Sun Sep 13 13:58:46 2015 (r287752, copy of r287148, head/bin/sh/tests/builtins/case20.0) @@ -0,0 +1,9 @@ +# $FreeBSD$ + +# Shells do not agree about what this pattern should match, but it is +# certain that it must not crash and the missing close bracket must not +# be simply ignored. + +case B in +[[:alpha:]) echo bad ;; +esac