Skip to content

Commit 9fee989

Browse files
update test and fix error checking
1 parent 342136d commit 9fee989

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

ci/tests.bats

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ function teardown() {
5555
run squashfs-mount ${SQFSDIR}/tools-offset.sqfs@2048:/user-tools -- cat /user-tools/tools/fileB.txt
5656
}
5757

58+
@test "mount_offset_image_neg_offset" {
59+
# offset must be > 0
60+
run squashfs-mount ${SQFSDIR}/tools-offset.sqfs@-2048434:/user-tools -- cat /user-tools/tools/fileB.txt
61+
assert_failure
62+
assert_line --regexp ".*offset.* must be >0: .*"
63+
}
64+
65+
@test "mount_offset_image_offset_twice" {
66+
# only one @<offset> is allowed
67+
run squashfs-mount ${SQFSDIR}/tools-offset.sqfs@2@2:/user-tools -- cat /user-tools/tools/fileB.txt
68+
assert_failure
69+
assert_line --regexp ".*invalid format: .*"
70+
}
71+
5872
@test "mount_images" {
5973
run squashfs-mount ${SQFSDIR}/binaries.sqfs:/user-environment ${SQFSDIR}/profilers.sqfs:/user-profilers ${SQFSDIR}/tools.sqfs:/user-tools -- cat /user-environment/spack-install/fileA.txt
6074
}

squashfs-mount.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,21 @@ static mount_entry_t *parse_mount_entries(const char **argv, int argc) {
195195
}
196196
// if @offset is present, attempt to parse offset
197197
if ((offset_str = strtok(NULL, "@"))) {
198-
char *endptr;
199198
// check if value is negative
200-
if (strtoll(offset_str, NULL, 10) < 0) {
201-
errx(EXIT_FAILURE, "invalid value in offset: %s", argv[i]);
199+
long long _f;
200+
if ((_f = strtoll(offset_str, NULL, 10)) < 0) {
201+
errx(EXIT_FAILURE, "offset (=%lld) must be >0: %s", _f, argv[i]);
202202
}
203203
// parse offset
204+
char *endptr;
204205
offset = strtoul(offset_str, &endptr, 10);
205-
if (errno != 0 || *endptr != '\0') {
206-
errx(EXIT_FAILURE, "invalid value in offset: %s", argv[i]);
206+
if (*endptr != '\0') {
207+
errx(EXIT_FAILURE, "invalid value in offset: %s from %s", offset_str, argv[i]);
208+
}
209+
// expect file_and_offset only contains one `@`
210+
if (strtok(NULL, "@")) {
211+
errx(EXIT_FAILURE, "invalid format: %s", argv[i]);
207212
}
208-
}
209-
// expect file_and_offset only contains one `@`
210-
if (strtok(NULL, "@")) {
211-
errx(EXIT_FAILURE, "invalid format %s", argv[i]);
212213
}
213214

214215
strcpy(mount_entries[i].squashfs_file, file);

0 commit comments

Comments
 (0)