Skip to content

Commit

Permalink
dumpfile: Deny content being set for non-regfiles
Browse files Browse the repository at this point in the history
Just additional validation.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Sep 16, 2024
1 parent 464d354 commit dd6ea60
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions rust/composefs/src/dumpfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ impl<'p> Entry<'p> {
fsverity_digest: fsverity_digest.map(ToOwned::to_owned),
},
libc::S_IFLNK => {
if content.is_some() {
anyhow::bail!("symlinks cannot have content");
}
// Note that the target of *symlinks* is not required to be in canonical form,
// as we don't actually traverse those links on our own, and we need to support
// symlinks that e.g. contain `//` or other things.
Expand All @@ -399,9 +402,24 @@ impl<'p> Entry<'p> {
}
Item::Symlink { nlink, target }
}
libc::S_IFIFO => Item::Fifo { nlink },
libc::S_IFCHR | libc::S_IFBLK => Item::Device { nlink, rdev },
libc::S_IFDIR => Item::Directory { size, nlink },
libc::S_IFIFO => {
if content.is_some() {
anyhow::bail!("entry cannot have content");
}
Item::Fifo { nlink }
}
libc::S_IFCHR | libc::S_IFBLK => {
if content.is_some() {
anyhow::bail!("entry cannot have content");
}
Item::Device { nlink, rdev }
}
libc::S_IFDIR => {
if content.is_some() {
anyhow::bail!("entry cannot have content");
}
Item::Directory { size, nlink }
}
o => {
anyhow::bail!("Unhandled mode {o:o}")
}
Expand Down Expand Up @@ -773,6 +791,10 @@ mod tests {
"dir hardlink",
include_str!("../../../tests/assets/should-fail-dir-hardlink.dump"),
),
(
"content in fifo",
"/ 4096 40755 2 0 0 0 0.0 - - -\n/fifo 0 10777 1 0 0 0 0.0 - foobar -",
),
];
for (name, case) in CASES.iter().copied() {
assert!(
Expand Down

0 comments on commit dd6ea60

Please sign in to comment.