8568 fnmatch, glob: fix exponential CPU use with repeated '*' operators

Review Request #647 — Created Aug. 14, 2017 and submitted

yuripv
illumos-gate
master
8568
4d224ee...
general

Pull the fix for fnmatch(3C) from FreeBSD and for glob(3C) from OpenBSD (along with a bit of cleanup).

Note that this will NOT help with ls a*a*a*a*a*a*a*b in e.g. bash, which uses its own glob code.

Timed the following test cases:

$ cat g.c
#include <glob.h>

int
main(void)
{
        glob_t g;

        glob("~/a*a*a*a*a*a*a*a*a*a*a*b", GLOB_TILDE, NULL, &g);
        globfree(&g);

        return (0);
}
$ cat f.c
#include <fnmatch.h>

int
main(void)
{

        fnmatch("a*a*a*a*a*a*b", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0);

        return (0);
}
$
igork
  1. Ship It!
  2. 
      
andy_js
  1. Ship It!
  2. 
      
tsoome
  1. Ship It!
  2. 
      
yuripv
Review request changed

Status: Closed (submitted)

Loading...