summaryrefslogtreecommitdiffstats
path: root/src/util.cc
diff options
context:
space:
mode:
authorScott Graham <scottmg@chromium.org>2014-11-12 17:16:25 (GMT)
committerScott Graham <scottmg@chromium.org>2014-11-12 17:16:25 (GMT)
commitcc8b72a87d72a030dc5b2bb212958c0e46213a6b (patch)
treec0cbdf6e814038385bad3945b2229e7dd611eb00 /src/util.cc
parent0c2982d13ea290a451efa8e8ddbaa9af1e7229a1 (diff)
downloadNinja-cc8b72a87d72a030dc5b2bb212958c0e46213a6b.zip
Ninja-cc8b72a87d72a030dc5b2bb212958c0e46213a6b.tar.gz
Ninja-cc8b72a87d72a030dc5b2bb212958c0e46213a6b.tar.bz2
properly guard against slash_bits overflow
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/util.cc b/src/util.cc
index e667992..4df81dd 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -130,9 +130,9 @@ bool CanonicalizePath(char* path, size_t* len, unsigned int* slash_bits,
const char* end = start + *len;
#ifdef _WIN32
- // kMaxPathComponents protects this from overflowing.
unsigned int bits = 0;
unsigned int bits_mask = 1;
+ int bits_offset = 0;
// Convert \ to /, setting a bit in |bits| for each \ encountered.
for (char* c = path; c < end; ++c) {
switch (*c) {
@@ -142,9 +142,12 @@ bool CanonicalizePath(char* path, size_t* len, unsigned int* slash_bits,
// Intentional fallthrough.
case '/':
bits_mask <<= 1;
+ bits_offset++;
}
}
- int bits_offset = 0;
+ if (bits_offset > 32)
+ return false;
+ bits_offset = 0;
#endif
if (*src == '/') {