summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2023-11-15 18:56:54 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2023-11-15 18:56:54 +0000
commit144e76688ef2c3ec189a90e969bfbb44fc361d15 (patch)
treef17737d68dd9e6f4b63e782a1c59280ed63c215b /usr.bin
parentdcc602ff94f5b4705b551c71782dd97083882059 (diff)
fnematch: fix a bug that could result in extra chars being pushed back.
From Arnold Robbins. https://github.com/onetrueawk/awk/pull/213
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/awk/b.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c
index ab0228b9c63..543fbf798c7 100644
--- a/usr.bin/awk/b.c
+++ b/usr.bin/awk/b.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: b.c,v 1.46 2023/11/15 18:48:13 millert Exp $ */
+/* $OpenBSD: b.c,v 1.47 2023/11/15 18:56:53 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -905,13 +905,10 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
* (except for EOF's nullbyte, if present) and null
* terminate the buffer.
*/
- do {
- int ii;
- for (ii = r.len; ii > 0; ii--)
- if (buf[--k] && ungetc(buf[k], f) == EOF)
- FATAL("unable to ungetc '%c'", buf[k]);
- } while (k > i + patlen);
- buf[k] = '\0';
+ for (; r.len > 0; r.len--)
+ if (buf[--k] && ungetc(buf[k], f) == EOF)
+ FATAL("unable to ungetc '%c'", buf[k]);
+ buf[k-patlen] = '\0';
return true;
}
else