]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: fix repeat search crash
authorSami Kerola <kerolasa@iki.fi>
Tue, 27 Jan 2015 22:28:57 +0000 (22:28 +0000)
committerKarel Zak <kzak@redhat.com>
Wed, 28 Jan 2015 07:27:45 +0000 (08:27 +0100)
Repeating a search for a pattern that did not found made more(1) to
crash.  To reproduce 'more /etc/services' and search for 'doom'; you will
find a service in port 666 - pressing '.' after that result used to cause
core dump.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
text-utils/more.c

index 74148a7abb45b705c21e215ada54975c995af8f3..94b04550690da0b989f3781aae298b9fe5475d81 100644 (file)
@@ -1605,6 +1605,8 @@ void search(char buf[], FILE *file, register int n)
        context.line = saveln = Currline;
        context.chrctr = startline;
        lncount = 0;
+       if (!buf)
+               goto notfound;
        if ((rc = regcomp(&re, buf, REG_NOSUB)) != 0) {
                char s[REGERR_BUF];
                regerror(rc, &re, s, sizeof s);
@@ -1661,6 +1663,7 @@ void search(char buf[], FILE *file, register int n)
                }
                free(previousre);
                previousre = NULL;
+notfound:
                more_error(_("Pattern not found"));
        }
 }