diff options
author | George Rimar <grimar@accesssoftek.com> | 2017-07-31 09:26:50 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2017-07-31 09:26:50 +0000 |
commit | e36d7a6d68705020fe755d5b23f48dea247643cb (patch) | |
tree | d16f09a638d398d570f7d125ece9dd3d68440c11 /llvm/lib/Support/GlobPattern.cpp | |
parent | 7ef3a19337c69772e1f95e6be322fa27388f0f34 (diff) | |
download | bcm5719-llvm-e36d7a6d68705020fe755d5b23f48dea247643cb.tar.gz bcm5719-llvm-e36d7a6d68705020fe755d5b23f48dea247643cb.zip |
[Support/GlobPattern] - Do not crash when pattern has characters with int value < 0.
Found it during work on LLD, it would crash on following
linker script:
SECTIONS { .foo : { *("*®") } }
That happens because ® has int value -82. And chars are used as
array index in code, and are signed by default.
Differential revision: https://reviews.llvm.org/D35891
llvm-svn: 309549
Diffstat (limited to 'llvm/lib/Support/GlobPattern.cpp')
-rw-r--r-- | llvm/lib/Support/GlobPattern.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/llvm/lib/Support/GlobPattern.cpp b/llvm/lib/Support/GlobPattern.cpp index 8ee2febeeea..4ea110301f1 100644 --- a/llvm/lib/Support/GlobPattern.cpp +++ b/llvm/lib/Support/GlobPattern.cpp @@ -33,27 +33,30 @@ static Expected<BitVector> expand(StringRef S, StringRef Original) { if (S.size() < 3) break; + uint8_t Start = S[0]; + uint8_t End = S[2]; + // If it doesn't start with something like X-Y, // consume the first character and proceed. if (S[1] != '-') { - BV[S[0]] = true; + BV[Start] = true; S = S.substr(1); continue; } // It must be in the form of X-Y. // Validate it and then interpret the range. - if (S[0] > S[2]) + if (Start > End) return make_error<StringError>("invalid glob pattern: " + Original, errc::invalid_argument); - for (int C = S[0]; C <= S[2]; ++C) - BV[C] = true; + for (int C = Start; C <= End; ++C) + BV[(uint8_t)C] = true; S = S.substr(3); } for (char C : S) - BV[C] = true; + BV[(uint8_t)C] = true; return BV; } @@ -89,7 +92,7 @@ static Expected<BitVector> scan(StringRef &S, StringRef Original) { } default: BitVector BV(256, false); - BV[S[0]] = true; + BV[(uint8_t)S[0]] = true; S = S.substr(1); return BV; } @@ -159,7 +162,7 @@ bool GlobPattern::matchOne(ArrayRef<BitVector> Pats, StringRef S) const { } // If Pats[0] is not '*', it must consume one character. - if (S.empty() || !Pats[0][S[0]]) + if (S.empty() || !Pats[0][(uint8_t)S[0]]) return false; Pats = Pats.slice(1); S = S.substr(1); |