Date: Sat, 20 May 2017 00:42:47 +0000 (UTC) From: Ed Maste <emaste@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318565 - head/usr.bin/grep Message-ID: <201705200042.v4K0glEV014982@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: emaste Date: Sat May 20 00:42:47 2017 New Revision: 318565 URL: https://svnweb.freebsd.org/changeset/base/318565 Log: 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. PR: 219402 Submitted by: Kyle Evans <kevans91@ksu.edu> Reviewed by: cem Differential Revision: https://reviews.freebsd.org/D10820 Modified: head/usr.bin/grep/file.c Modified: head/usr.bin/grep/file.c ============================================================================== --- head/usr.bin/grep/file.c Sat May 20 00:41:12 2017 (r318564) +++ head/usr.bin/grep/file.c Sat May 20 00:42:47 2017 (r318565) @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705200042.v4K0glEV014982>