1) GLOB_BRACE was somewhat broken. First it repeatedly calls glob0() in
authorache <ache@FreeBSD.org>
Thu, 21 Jul 2016 12:53:36 +0000 (12:53 +0000)
committerache <ache@FreeBSD.org>
Thu, 21 Jul 2016 12:53:36 +0000 (12:53 +0000)
commit8ccc77aac2442ef09ab48065a28313c164d87141
tree2d46b9aa03e41202793ccf921685b95432ebd600
parent3100997739ca526d8a6e1abe3baf37390ec79523
1) GLOB_BRACE was somewhat broken. First it repeatedly calls glob0() in
globexp1() recursive calls, but glob0() was not supposed to be called
repeatedly in the original code. It finalize results by possible adding
original pattern for no match case, may return GLOB_NOMATCH error and
by sorting all things. Original pattern adding or GLOB_NOMATCH error
can happens each time glob0() called repeatedly, and sorting happens
for one item only, all things are never sorted. Second, f.e. "a{a"
pattern does not match "a{a" file but match "a" file instead
(just one example, there are many). Third, some errors (f.e. for limits
or overflow) can be ignored by GLOB_BRACE code because it forces return (0).
Add non-finalizing flag to glob0() and make globexp0() wrapper around
recursively called globexp1() to finalize things like glob0() does.
Reorganize braces code to work correctly.

2) Don't allow MB_CUR_MAX * strlen overallocation hits GLOB_LIMIT_STRING
(ARG_MAX) limit, use final string length, not malloced space for it.

3) Revive DEBUG-ifdefed section.
lib/libc/gen/glob.c