summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorkevans <kevans@FreeBSD.org>2017-08-17 04:18:31 +0000
committerkevans <kevans@FreeBSD.org>2017-08-17 04:18:31 +0000
commit66ff5b080a97728a17f338222b1bec9dff646980 (patch)
tree328cfdef7c173533a5e05cbd25a60faf4103ef1f /usr.bin
parente4d500149703035432c35df48506b8bf7237edef (diff)
downloadFreeBSD-src-66ff5b080a97728a17f338222b1bec9dff646980.zip
FreeBSD-src-66ff5b080a97728a17f338222b1bec9dff646980.tar.gz
bsdgrep: fix segfault with --mmap and add relevant test
MFC r318565: bsdgrep: fix segfault with --mmap r313948 partially fixed --mmap behavior but was incomplete. This commit generally reverts it and does it the more correct way- by just consuming the rest of the buffer and moving on. MFC r318908: bsdgrep: add --mmap tests Basic sanity tests as well as coverage for the bug fixed in r318565. PR: 219402 Approved by: emaste (mentor, blanket MFC)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/grep/file.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/usr.bin/grep/file.c b/usr.bin/grep/file.c
index 7ed34d9..bea7c72 100644
--- a/usr.bin/grep/file.c
+++ b/usr.bin/grep/file.c
@@ -213,24 +213,24 @@ grep_fgetln(struct file *f, size_t *lenp)
if (grep_lnbufgrow(len + LNBUFBUMP))
goto error;
memcpy(lnbuf + off, bufpos, len - off);
+ /* With FILE_MMAP, this is EOF; there's no more to refill */
+ if (filebehave == FILE_MMAP) {
+ bufrem -= len;
+ break;
+ }
off = len;
+ /* Fetch more to try and find EOL/EOF */
if (grep_refill(f) != 0)
goto error;
if (bufrem == 0)
/* EOF: return partial line */
break;
- if ((p = memchr(bufpos, fileeol, bufrem)) == NULL &&
- filebehave != FILE_MMAP)
+ if ((p = memchr(bufpos, fileeol, bufrem)) == NULL)
continue;
- if (p == NULL) {
- /* mmap EOF: return partial line, consume buffer */
- diff = len;
- } else {
- /* got it: finish up the line (like code above) */
- ++p;
- diff = p - bufpos;
- len += diff;
- }
+ /* got it: finish up the line (like code above) */
+ ++p;
+ diff = p - bufpos;
+ len += diff;
if (grep_lnbufgrow(len))
goto error;
memcpy(lnbuf + off, bufpos, diff);
OpenPOWER on IntegriCloud