mirror of
https://github.com/NixOS/nix.git
synced 2024-11-25 00:02:25 +00:00
GitFileSystemObjectSink: catch an overflow
This commit is contained in:
parent
a409c1a882
commit
f0329568b5
@ -931,6 +931,8 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink
|
|||||||
++dir;
|
++dir;
|
||||||
relTargetLeft = relTargetLeft.substr(3);
|
relTargetLeft = relTargetLeft.substr(3);
|
||||||
}
|
}
|
||||||
|
if (dir == pendingDirs.rend())
|
||||||
|
throw Error("invalid hard link target '%s' for path '%s'", target, path);
|
||||||
|
|
||||||
// Look up the remainder of the target, starting at the
|
// Look up the remainder of the target, starting at the
|
||||||
// top-most `git_treebuilder`.
|
// top-most `git_treebuilder`.
|
||||||
|
@ -87,4 +87,24 @@ TEST_F(GitUtilsTest, sink_basic)
|
|||||||
ASSERT_EQ(accessor->readFile(CanonPath("links/foo")), "hello world");
|
ASSERT_EQ(accessor->readFile(CanonPath("links/foo")), "hello world");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TEST_F(GitUtilsTest, sink_hardlink)
|
||||||
|
{
|
||||||
|
auto repo = openRepo();
|
||||||
|
auto sink = repo->getFileSystemObjectSink();
|
||||||
|
|
||||||
|
sink->createDirectory("foo-1.1");
|
||||||
|
|
||||||
|
sink->createRegularFile(
|
||||||
|
"foo-1.1/hello", [](CreateRegularFileSink & fileSink) { writeString(fileSink, "hello world", false); });
|
||||||
|
|
||||||
|
try {
|
||||||
|
sink->createHardlink("foo-1.1/link", CanonPath("hello"));
|
||||||
|
FAIL() << "Expected an exception";
|
||||||
|
} catch (const nix::Error & e) {
|
||||||
|
ASSERT_THAT(e.msg(), testing::HasSubstr("invalid hard link target"));
|
||||||
|
ASSERT_THAT(e.msg(), testing::HasSubstr("/hello"));
|
||||||
|
ASSERT_THAT(e.msg(), testing::HasSubstr("foo-1.1/link"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
|
Loading…
Reference in New Issue
Block a user