Skip to content

Commit

Permalink
Fix glob pattern matching regression.
Browse files Browse the repository at this point in the history
Static analysis indicated that the GLOB_META_* macros should be casted to
CHARs. They were being compared to CHARs throughout the glob code. This
change broke ClpGlobMatch, causing an entire switch statement to be
compiled out due to integer promotion differences between the GLOB_META_*
CHAR macros and a CHAR being AND'd with 0xFF.

The fix is to remove the GLOB_META_MASK (0xFF). It is not needed as the
GLOBL_META_* macros are only ever being compared to CHARs.
  • Loading branch information
ccstevens committed Nov 8, 2016
1 parent 84112ca commit 771d8d6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions apps/libc/dynamic/glob.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ Module Name:

#define GLOB_META_QUOTE 0x80
#define GLOB_META_PROTECT 0x40
#define GLOB_META_MASK 0xFF
#define GLOB_META_CHARACTER_MASK 0x7F

#define GLOB_META_ALL GLOB_MAKE_META('*')
Expand Down Expand Up @@ -798,7 +797,7 @@ Return Value:
//

if ((CurrentBuffer == PatternBuffer) ||
((UCHAR)*(CurrentBuffer - 1) != GLOB_META_ALL)) {
(*(CurrentBuffer - 1) != GLOB_META_ALL)) {

*CurrentBuffer = GLOB_META_ALL;
CurrentBuffer += 1;
Expand Down Expand Up @@ -1252,7 +1251,7 @@ Return Value:
while (Pattern < PatternEnd) {
PatternCharacter = *Pattern;
Pattern += 1;
switch (PatternCharacter & GLOB_META_MASK) {
switch (PatternCharacter) {
case GLOB_META_ALL:
if (Pattern == PatternEnd) {
return TRUE;
Expand Down Expand Up @@ -1289,19 +1288,19 @@ Return Value:
}

Negated = FALSE;
if ((*Pattern & GLOB_META_MASK) == GLOB_META_NOT) {
if (*Pattern == GLOB_META_NOT) {
Negated = TRUE;
Pattern += 1;
}

while (TRUE) {
PatternCharacter = *Pattern;
Pattern += 1;
if ((PatternCharacter & GLOB_META_MASK) == GLOB_META_END) {
if (PatternCharacter == GLOB_META_END) {
break;
}

if ((*Pattern & GLOB_META_MASK) == GLOB_META_RANGE) {
if (*Pattern == GLOB_META_RANGE) {
if ((GLOB_CHARACTER(NameCharacter) >=
GLOB_CHARACTER(PatternCharacter)) &&
(GLOB_CHARACTER(NameCharacter) <=
Expand Down

0 comments on commit 771d8d6

Please sign in to comment.