aboutsummaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-09-28 16:59:01 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-09-28 16:59:01 -0700
commita61efe2cf0b10da82d529d8fced95a44facf8c5d (patch)
tree1f0afc4b78e43e4f0709bbbe1c622a9eab3387ad /match.c
parent46fa8565298a1cc9a883fbda353f097d85d170ec (diff)
Hardening utils (added *end param to avoid going past the end of
unterminated strings)
Diffstat (limited to 'match.c')
-rw-r--r--match.c10
1 files changed, 5 insertions, 5 deletions
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;