Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fnematch: fix out-of-bounds access on EOF #211

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions b.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,15 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
j = i++;
do {
r = getrune(f);
if ((++j + r.len) >= k) {
if (k >= bufsize)
if (!adjbuf((char **) &buf, &bufsize, bufsize+1, quantum, 0, "fnematch"))
FATAL("stream '%.30s...' too long", buf);
if (r.len == 0) {
r.len = 1; // store NUL byte for EOF
}
j += r.len;
if (j >= bufsize) {
if (!adjbuf((char **) &buf, &bufsize, j+1, quantum, 0, "fnematch"))
FATAL("stream '%.30s...' too long", buf);
}
memcpy(buf + k, r.bytes, r.len);
j += r.len - 1; // incremented next time around the loop
k += r.len;

if ((ns = get_gototab(pfa, s, r.rune)) != 0)
Expand Down