Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify payload length early on #310

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libcomposefs/lcfs-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,11 @@ int lcfs_node_set_payload(struct lcfs_node_s *node, const char *payload)
{
char *dup = NULL;
if (payload) {
const size_t len = strlen(payload);
if (len >= PATH_MAX) {
errno = ENAMETOOLONG;
return -1;
}
dup = strdup(payload);
if (dup == NULL) {
errno = ENOMEM;
Expand Down
8 changes: 7 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ TEST_ASSETS_SMALL = \
TEST_ASSETS_SMALL_EXTRA = \
special.dump.version special_v1.dump.version

TEST_ASSETS_SHOULD_FAIL = should-fail-long-link.dump
TEST_ASSETS = ${TEST_ASSETS_SMALL} \
cs9-x86_64-developer.dump.gz cs9-x86_64-minimal.dump.gz \
f36-x86_64-silverblue.dump.gz
Expand All @@ -19,17 +20,22 @@ EXTRA_DIST = \
test-units.sh \
test-random-fuse.sh \
test-checksums.sh \
test-should-fail.sh \
integration.sh \
$(patsubst %,assets/%,${TEST_ASSETS_SMALL_EXTRA}) \
$(patsubst %,assets/%,${TEST_ASSETS_SHOULD_FAIL}) \
$(patsubst %,assets/%,${TEST_ASSETS_SMALL}) $(patsubst %,assets/%.sha256,${TEST_ASSETS_SMALL})

check-checksums:
VALGRIND_PREFIX="${VALGRIND_PREFIX}" $(srcdir)/test-checksums.sh "$(builddir)/../tools/" "$(srcdir)/assets" "${TEST_ASSETS}"

check-should-fail:
$(srcdir)/test-should-fail.sh ${TEST_ASSETS_SHOULD_FAIL}

check-units:
VALGRIND_PREFIX="${VALGRIND_PREFIX}" $(srcdir)/test-units.sh "$(builddir)/../tools/"

check-random-fuse:
VALGRIND_PREFIX="${VALGRIND_PREFIX}" $(srcdir)/test-random-fuse.sh "$(builddir)/../tools/"

check: check-units check-checksums check-random-fuse
check: check-units check-checksums check-random-fuse check-should-fail
2 changes: 2 additions & 0 deletions tests/assets/should-fail-long-link.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/ 4096 40555 2 0 0 0 1633950376.0 - - - -
/link 5 120777 1 0 0 0 0.0 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - -
8 changes: 8 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ test_assets_small_extra = [
'special_v1.dump.version',
]

test_assets_should_fail = [
'should-fail-long-link.dump'
]

test_assets = test_assets_small + [
'cs9-x86_64-developer.dump.gz',
'cs9-x86_64-minimal.dump.gz',
Expand All @@ -23,9 +27,13 @@ extra_dist = [
'test-units.sh',
'test-random-fuse.sh',
'test-checksums.sh',
'test-should-fail.sh',
'integration.sh',
]

foreach asset : test_assets_should_fail
extra_dist += ['assets/' + asset]
endforeach
foreach asset : test_assets_small_extra
extra_dist += ['assets/' + asset]
endforeach
Expand Down
1 change: 1 addition & 0 deletions tests/test-checksums.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
BINDIR="$1"
ASSET_DIR="$2"
TEST_ASSETS="$3"
TEST_ASSETS_SHOULD_FAIL="$4"

. $(dirname $0)/test-lib.sh

Expand Down
14 changes: 14 additions & 0 deletions tests/test-should-fail.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
cases=$1
. $(dirname $0)/test-lib.sh

set -e
tmpfile=$(mktemp -d -t lcfs-test.XXXXXX)
cd $tmpfile
trap 'rm -rf -- "$tmpfile"' EXIT
for f in $cases; do
if mkcomposefs --from-file $f >/dev/null 2>err.txt; then
fatal "Test case $f should have failed"
fi
echo "ok $f"
done
3 changes: 2 additions & 1 deletion tools/mkcomposefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ static char *tree_from_dump_line(dump_info *info, const char *line, size_t line_
lcfs_node_set_gid(node, gid);
lcfs_node_set_rdev(node, rdev);
lcfs_node_set_mtime(node, &mtime);
lcfs_node_set_payload(node, payload);
if (lcfs_node_set_payload(node, payload) < 0)
return make_error("Invalid payload");
if (content) {
ret = lcfs_node_set_content(node, (uint8_t *)content, size);
if (ret < 0)
Expand Down
Loading