diff options
author | Evan Martin <martine@danga.com> | 2012-02-04 22:14:04 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-02-04 22:14:04 (GMT) |
commit | e9087f5cdf2c8485b5b0a6858782bb02dbffbcdd (patch) | |
tree | e912ce9b60f0400d33825cdde127848db95813de /src | |
parent | 06315b1e2e2db9ba5dbb1d4ecf91344846c0de3a (diff) | |
download | Ninja-e9087f5cdf2c8485b5b0a6858782bb02dbffbcdd.zip Ninja-e9087f5cdf2c8485b5b0a6858782bb02dbffbcdd.tar.gz Ninja-e9087f5cdf2c8485b5b0a6858782bb02dbffbcdd.tar.bz2 |
don't crash when CanonicalizePath removes all path components
From a patch from Peter Kuemmel <syntheticpp@gmx.net>.
Diffstat (limited to 'src')
-rw-r--r-- | src/util.cc | 5 | ||||
-rw-r--r-- | src/util_test.cc | 17 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc index 1dd9838..02be994 100644 --- a/src/util.cc +++ b/src/util.cc @@ -148,6 +148,11 @@ bool CanonicalizePath(char* path, int* len, string* err) { src = sep + 1; } + if (dst == start) { + *err = "path canonicalizes to the empty path"; + return false; + } + *len = dst - start - 1; return true; } diff --git a/src/util_test.cc b/src/util_test.cc index c44ab77..5b6b164 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -54,6 +54,23 @@ TEST(CanonicalizePath, PathSamples) { path = "./x/../foo/../../bar.h"; EXPECT_TRUE(CanonicalizePath(&path, &err)); EXPECT_EQ("../bar.h", path); + + path = "foo/./."; + EXPECT_TRUE(CanonicalizePath(&path, &err)); + EXPECT_EQ("foo", path); +} + +TEST(CanonicalizePath, EmptyResult) { + string path; + string err; + + path = "."; + EXPECT_FALSE(CanonicalizePath(&path, &err)); + EXPECT_EQ("path canonicalizes to the empty path", err); + + path = "./."; + EXPECT_FALSE(CanonicalizePath(&path, &err)); + EXPECT_EQ("path canonicalizes to the empty path", err); } TEST(CanonicalizePath, UpDir) { |