about summary refs log tree commit diff
path: root/src/regex
diff options
context:
space:
mode:
authorJulien Ramseier <j.ramseier@gmail.com>2017-03-21 12:24:23 -0400
committerRich Felker <dalias@aerifal.cx>2017-03-21 12:24:23 -0400
commit9571c5314a8064eda8a56faa2ae2aeced34497a3 (patch)
tree9120ec538b42accd4bf44c73c66f20943cd8ad81 /src/regex
parente6917eced2cc841fe3dfd9c04deec9202f9e34f3 (diff)
downloadmusl-9571c5314a8064eda8a56faa2ae2aeced34497a3.tar.gz
musl-9571c5314a8064eda8a56faa2ae2aeced34497a3.tar.xz
musl-9571c5314a8064eda8a56faa2ae2aeced34497a3.zip
regex: fix newline matching with negated brackets
With REG_NEWLINE, POSIX says:
"A <newline> in string shall not be matched by a period outside
a bracket expression or by any form of a non-matching list"
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/regcomp.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c
index 5a7b53a7..fb24556e 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 */