set *err when too many components in CanonicalizePath
authorScott Graham <scottmg@chromium.org>
Wed, 12 Nov 2014 20:32:45 +0000 (12:32 -0800)
committerScott Graham <scottmg@chromium.org>
Wed, 12 Nov 2014 20:32:45 +0000 (12:32 -0800)
src/util.cc
src/util_test.cc

index 4df81dd..7717ef4 100644 (file)
@@ -145,8 +145,10 @@ bool CanonicalizePath(char* path, size_t* len, unsigned int* slash_bits,
         bits_offset++;
     }
   }
-  if (bits_offset > 32)
+  if (bits_offset > 32) {
+    *err = "too many path components";
     return false;
+  }
   bits_offset = 0;
 #endif
 
index 5bbf397..13730af 100644 (file)
@@ -272,15 +272,19 @@ TEST(CanonicalizePath, TooManyComponents) {
   EXPECT_EQ(slash_bits, 0xffff);
 
   // 33 is not.
+  err = "";
   path =
       "a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/x.h";
   EXPECT_FALSE(CanonicalizePath(&path, &slash_bits, &err));
+  EXPECT_EQ(err, "too many path components");
 
   // Backslashes version.
+  err = "";
   path =
       "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\."
       "\\a\\.\\a\\.\\a\\.\\a\\.\\a\\x.h";
   EXPECT_FALSE(CanonicalizePath(&path, &slash_bits, &err));
+  EXPECT_EQ(err, "too many path components");
 }
 #endif