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