CFT: BSD grep
gabor at kovesdan.org
Thu Sep 4 11:11:32 UTC 2008
Andrey Chernov ha scritto:
> Just from quick looking at the sources...
> This code looks suspicious:
> wend = sscanf(&l->dat[pmatch.rm_eo], "%lc", &wend);
> Perhaps it should be
> if (sscanf(&l->dat[pmatch.rm_eo], "%lc", &wend) != 1)
> r = REG_NOMATCH;
> The next thing is that perhaps each r = REG_NOMATCH; case should be
> isolated from others in this block (with "else if"?)
> F.e. failing mbstowcs() can leave buffer for sscanf() in junk.
> wbegin = grep_malloc(mbstowcs(NULL, l->dat, pmatch.rm_so));
> grep_malloc() here could terminate program for invalid mbstowcs()
> sequence, but really must set only r = REG_NOMATCH;
> Think about files which, for various reasons, may contain not only valid
> MB sequences.
> fgrepcomp() uses toupper()/tolower() while should use wide chars analogs
> (MB chars can be in the pattern too). There are also many other places
> where pattern treated as single chars one, fastcomp() etc. grep_cmp()
> compares single chars toupper(data) too. There must be no plain ctype
> usage in the whole data _and_ pattern handling code.
thanks for the detailed description of the current deficiencies, I'll
fix them soon. I've been busy with moving to another flat, that's why I
haven't replied yet, sorry for that.
More information about the freebsd-hackers