~sircmpwn/hare-dev

hare: regex: require quantifier minimum in range v1 APPLIED

Nolan Prescott: 1
 regex: require quantifier minimum in range

 2 files changed, 11 insertions(+), 3 deletions(-)
#744615 alpine.yml success
#744616 freebsd.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/31598/mbox | git am -3
Learn more about email & git

[PATCH hare] regex: require quantifier minimum in range Export this patch

Intended to address https://todo.sr.ht/~sircmpwn/hare/633 where
valgrind flags a conditional jump on uninitialized value(s) stemming
from regex.parse_repetition. The source of the uninitialized value
isn't called out in the ticket but is visible with:

  valgrind --track-origins=yes .bin/hare-tests regex::find

The POSIX ERE grammar[0] does not specify a quantifier syntax with
undefined minimums (e.g. `{,2}`), this patch will error in such a case
rather than use the void value with `rep_parts.0`

0: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_05_03
Signed-off-by: Nolan Prescott <mail@nprescott.com>
---
 regex/+test.ha | 10 +++++++---
 regex/regex.ha |  4 ++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/regex/+test.ha b/regex/+test.ha
index 5f59d04f..d28b41cc 100644
--- a/regex/+test.ha
+++ b/regex/+test.ha
@@ -304,13 +304,17 @@ fn run_findall_case(
		(`^a\|b$`, "a|b", matchres::MATCH, 0, -1),
		(`^a\.b$`, "a.b", matchres::MATCH, 0, -1),
		(`^a\\b$`, "a\\b", matchres::MATCH, 0, -1),
		(`^x(abc)\{,2\}$`, "xabc{,2}", matchres::MATCH, 0, -1),
		(`^x(abc)\{,2\}$`, "xabcabc{,2}", matchres::NOMATCH, 0, -1),
		// {m,n}
		(`^x(abc){2}$`, "xabcabc", matchres::MATCH, 0, -1),
		(`^x(abc){3}$`, "xabcabc", matchres::NOMATCH, 0, -1),
		(`^x(abc){1,2}$`, "xabc", matchres::MATCH, 0, -1),
		(`^x(abc){1,2}$`, "xabcabc", matchres::MATCH, 0, -1),
		(`^x(abc){1,2}$`, "xabcabcabc", matchres::NOMATCH, 0, -1),
		(`^x(abc){,2}$`, "xabc", matchres::MATCH, 0, -1),
		(`^x(abc){,2}$`, "xabcabc", matchres::MATCH, 0, -1),
		(`^x(abc){,2}$`, "xabcabcabc", matchres::NOMATCH, 0, -1),
		(`^x(abc){,2}$`, "xabc", matchres::ERROR, 0, -1),
		(`^x(abc){,2}$`, "xabcabc", matchres::ERROR, 0, -1),
		(`^x(abc){,2}$`, "xabcabcabc", matchres::ERROR, 0, -1),
		(`^x(abc){1,}$`, "xabc", matchres::MATCH, 0, -1),
		(`^x(abc){1,}$`, "xabcabc", matchres::MATCH, 0, -1),
		(`^x(abc){3,}$`, "xabcabc", matchres::NOMATCH, 0, -1),
diff --git a/regex/regex.ha b/regex/regex.ha
index c49be630..6de4f374 100644
--- a/regex/regex.ha
+++ b/regex/regex.ha
@@ -454,6 +454,10 @@ fn parse_repetition(
		};
	};

	if (len(min_str) == 0 && len(max_str) > 0) {
		return "Invalid repetition minimum value": error;
	};

	const rep_len = if (is_single_arg) {
		yield len(min_str);
	} else {
-- 
2.32.0
hare/patches: SUCCESS in 1m31s

[regex: require quantifier minimum in range][0] from [Nolan Prescott][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/31598
[1]: mailto:mail@nprescott.com

✓ #744615 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/744615
✓ #744616 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/744616
Thanks!

To git@git.sr.ht:~sircmpwn/hare
   85f25df5..1a118d90  master -> master