From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11148 Path: news.gmane.org!.POSTED!not-for-mail From: Julien Ramseier Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] regex: fix newline matching with negated brackets Date: Fri, 17 Mar 2017 14:33:02 +0100 Message-ID: <6600F15C-80E5-4CAE-8749-F77323C58D17@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_EAD8AA5B-345D-4BA8-95CE-4FC05593B3BB" X-Trace: blaine.gmane.org 1489757611 23521 195.159.176.226 (17 Mar 2017 13:33:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 17 Mar 2017 13:33:31 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11163-gllmg-musl=m.gmane.org@lists.openwall.com Fri Mar 17 14:33:22 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1cos0I-0004dD-Lk for gllmg-musl@m.gmane.org; Fri, 17 Mar 2017 14:33:14 +0100 Original-Received: (qmail 23852 invoked by uid 550); 17 Mar 2017 13:33:17 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 23811 invoked from network); 17 Mar 2017 13:33:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:message-id:date:to:mime-version; bh=qp8OqCAk5pr8Q1l2lWm2qgvKYMWJcF4Px5fexPVCNMc=; b=d93iSud8ifRhapeXP5zRBcLV8DMsaIvStz0EARXcpZRDfzlJJaYrneW3uQww9aOVtV 7O92yUUM7dLexLWhh6jVioXSonETv9Een5T6Oi50NQLqhqUNx3mFzz5DsRs45MaWb38t 0JrGc4YiwbjXj0XwPM4Z5gVPfZIB/EJvtV9X1E4uQ1Q7o3WyuySMcW2+FGMOy7tJaFUB lLJKSZDaLzxgnRcvsac3OLONhZQwDPvDYx0jate99yonamm5CkcmFhVYYY/T0x3s6PEx TTPP2dkAVcrowsn5Q54/X2AtI+RZVpxUk/9rYk0474W9PkqKlh8DT+YH4XTKB8ERjJL+ 6cgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:message-id:date:to:mime-version; bh=qp8OqCAk5pr8Q1l2lWm2qgvKYMWJcF4Px5fexPVCNMc=; b=msYOBumxg040BoBuqB2B/HsEuVKRSlBMy4+z0pQIxtNBrbWCck7Lzbwzzv9EiQf9nX +UPX80PQtT2g39ZamlrOV8/QndgH2DW9kNQruCfWPi/C84o3bnHHFXt40PuROz+Xwbat 9PXm3GWKjlWjXk6rj0ABTjJexKmA8mPuZNQl2Jc71CdoJLtVhpqWS1mpqK5tYCxY42nC Sp7Yy1RtqmbpmNS7dm5h1VNMEs5xOBWtbBX91mhfXBe1PUTffTAejDCeM4WkIGT5pcc6 Dof0L9Pl849W6CkI9PDjg4UV1OSQ7iLbi0f/yh0Uu+bwpKeeHwsN7PjQP35+QnNol1W3 AeZw== X-Gm-Message-State: AFeK/H3iRwsFRrViJQbqUkDLN/AzpHjaTOgB+h+szlpwQi8Y9nWdWs4XFx3N2y1489VZow== X-Received: by 10.223.169.161 with SMTP id b30mr13583566wrd.196.1489757584066; Fri, 17 Mar 2017 06:33:04 -0700 (PDT) X-Mailer: Apple Mail (2.3124) Xref: news.gmane.org gmane.linux.lib.musl.general:11148 Archived-At: --Apple-Mail=_EAD8AA5B-345D-4BA8-95CE-4FC05593B3BB Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii With REG_NEWLINE, POSIX says: "A in string shall not be matched by a period outside a bracket expression or by any form of a non-matching list" musl currently matches newlines with negated brackets, even if REG_NEWLINE is used. Attached patch fixes the issue, although I'm not sure if it's the best way to do it. Also see similar glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3957 --Apple-Mail=_EAD8AA5B-345D-4BA8-95CE-4FC05593B3BB Content-Disposition: attachment; filename=regcomp-newline-neg-bracket.patch Content-Type: application/octet-stream; name="regcomp-newline-neg-bracket.patch" Content-Transfer-Encoding: 7bit diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c index 5a7b53a..fb24556 100644 --- a/src/regex/regcomp.c +++ b/src/regex/regcomp.c @@ -636,6 +636,20 @@ static reg_errcode_t parse_bracket(tre_parse_ctx_t *ctx, const char *s) goto parse_bracket_done; if (neg.negate) { + /* + * With REG_NEWLINE, POSIX requires that newlines are not matched by + * any form of a non-matching list. + */ + if (ctx->cflags & REG_NEWLINE) { + lit = tre_new_lit(&ls); + if (!lit) { + err = REG_ESPACE; + goto parse_bracket_done; + } + lit->code_min = '\n'; + lit->code_max = '\n'; + lit->position = -1; + } /* Sort the array if we need to negate it. */ qsort(ls.a, ls.len, sizeof *ls.a, tre_compare_lit); /* extra lit for the last negated range */ --Apple-Mail=_EAD8AA5B-345D-4BA8-95CE-4FC05593B3BB--