From 21bd32e7b47ce9d8c9ca93380993254ba62ffd66 Mon Sep 17 00:00:00 2001 From: gjb Date: Fri, 20 Jun 2014 21:53:50 +0000 Subject: Fix a bug in bsdgrep(1) where patterns are not correctly detected. Certain criteria must be met for this bug to show up: * the -w flag is specified, and * neither -o or --color are specified, and * the pattern is part of another word in the line, and * the other word that contains the pattern occurs first PR: 181973 MFC after: 3 days Sponsored by: The FreeBSD Foundation --- usr.bin/grep/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr.bin/grep') diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 0a3706f..15b2da7 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -336,7 +336,7 @@ procline(struct str *l, int nottext) } /* One pass if we are not recording matches */ - if ((color == NULL && !oflag) || qflag || lflag) + if (!wflag && ((color == NULL && !oflag) || qflag || lflag)) break; if (st == (size_t)pmatch.rm_so) -- cgit v1.1 From bcd1a4acd05f39f35ed9d7dd88c24cd1bb0d0cff Mon Sep 17 00:00:00 2001 From: pfg Date: Thu, 17 Jul 2014 14:51:50 +0000 Subject: grep: Fix type. Obtained from: NetBSD (CVS rev. 1.17) MFC after: 3 days --- usr.bin/grep/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr.bin/grep') diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 15b2da7..3ec12fa 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -302,7 +302,7 @@ procline(struct str *l, int nottext) r = REG_NOMATCH; /* Check for whole word match */ if (r == 0 && (wflag || fg_pattern[i].word)) { - wint_t wbegin, wend; + wchar_t wbegin, wend; wbegin = wend = L' '; if (pmatch.rm_so != 0 && -- cgit v1.1 From 642f571df9c895495cfc45b7c0c119609e561184 Mon Sep 17 00:00:00 2001 From: pfg Date: Thu, 17 Jul 2014 15:48:11 +0000 Subject: grep: fix some memory leaks. Bring a couple of changes from NetBSD: queue.c (CVS Rev. 1.4. 1.5) Fix memory leaks. NULL does not need a cast. grep.c (CVS Rev. 1.6) Use the more portable getline. Obtained from: NetBSD MFC after: 3 days --- usr.bin/grep/grep.c | 9 +++++++-- usr.bin/grep/queue.c | 15 ++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'usr.bin/grep') diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 74446b6..5631877 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.4 2011/02/16 01:31:33 joerg Exp $ */ +/* $NetBSD: grep.c,v 1.6 2011/04/18 03:48:23 joerg Exp $ */ /* $FreeBSD$ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#define _WITH_GETLINE #include #include #include @@ -304,6 +305,7 @@ read_patterns(const char *fn) FILE *f; char *line; size_t len; + ssize_t rlen; if ((f = fopen(fn, "r")) == NULL) err(2, "%s", fn); @@ -311,8 +313,11 @@ read_patterns(const char *fn) fclose(f); return; } - while ((line = fgetln(f, &len)) != NULL) + len = 0; + line = NULL; + while ((rlen = getline(&line, &len, f)) != -1) add_pattern(line, line[0] == '\n' ? 0 : len); + free(line); if (ferror(f)) err(2, "%s", fn); fclose(f); diff --git a/usr.bin/grep/queue.c b/usr.bin/grep/queue.c index afcb827..107d6e07 100644 --- a/usr.bin/grep/queue.c +++ b/usr.bin/grep/queue.c @@ -1,4 +1,4 @@ -/* $NetBSD: queue.c,v 1.2 2011/02/16 01:31:33 joerg Exp $ */ +/* $NetBSD: queue.c,v 1.5 2011/08/31 16:24:57 plunky Exp $ */ /* $FreeBSD$ */ /*- @@ -68,8 +68,11 @@ enqueue(struct str *x) STAILQ_INSERT_TAIL(&queue, item, list); - if (++count > Bflag) - free(dequeue()); + if (++count > Bflag) { + item = dequeue(); + free(item->data.dat); + free(item); + } } static struct qentry * @@ -92,7 +95,7 @@ printqueue(void) struct qentry *item; while ((item = dequeue()) != NULL) { - printline(&item->data, '-', (regmatch_t *)NULL, 0); + printline(&item->data, '-', NULL, 0); free(item); } } @@ -102,6 +105,8 @@ clearqueue(void) { struct qentry *item; - while ((item = dequeue()) != NULL) + while ((item = dequeue()) != NULL) { + free(item->data.dat); free(item); + } } -- cgit v1.1 From 31dcb2f8d46b176861e986fb800b35d3ee23db2b Mon Sep 17 00:00:00 2001 From: pfg Date: Thu, 17 Jul 2014 15:59:13 +0000 Subject: grep: fix some memory leaks. Add memory leak fix missing from r268799. Obtained from: NetBSD --- usr.bin/grep/queue.c | 1 + 1 file changed, 1 insertion(+) (limited to 'usr.bin/grep') diff --git a/usr.bin/grep/queue.c b/usr.bin/grep/queue.c index 107d6e07..1887888 100644 --- a/usr.bin/grep/queue.c +++ b/usr.bin/grep/queue.c @@ -96,6 +96,7 @@ printqueue(void) while ((item = dequeue()) != NULL) { printline(&item->data, '-', NULL, 0); + free(item->data.dat); free(item); } } -- cgit v1.1