From a61efe2cf0b10da82d529d8fced95a44facf8c5d Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 28 Sep 2021 16:59:01 -0700 Subject: Hardening utils (added *end param to avoid going past the end of unterminated strings) --- match.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'match.c') diff --git a/match.c b/match.c index 59b1765..2053a4f 100644 --- a/match.c +++ b/match.c @@ -911,10 +911,10 @@ void fprint_match(FILE *out, const char *file_start, match_t *m, print_options_t int n = (int)strtol(next, (char**)&next, 10); cap = get_numbered_capture(m->children[0], n); } else { - const char *name = next, *end = after_name(next); - if (end > name) { - cap = get_named_capture(m->children[0], name, (size_t)(end - name)); - next = end; + const char *name = next, *name_end = after_name(next, end); + if (name_end) { + cap = get_named_capture(m->children[0], name, (size_t)(name_end - name)); + next = name_end; if (next < m->end && *next == ';') ++next; } } @@ -941,7 +941,7 @@ void fprint_match(FILE *out, const char *file_start, match_t *m, print_options_t fputc(*p, out); continue; } - fputc_safe(out, unescapechar(r, &r), opts); + fputc_safe(out, unescapechar(r, &r, end), opts); } else { fputc_safe(out, *r, opts); ++r; -- cgit v1.2.3