aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/tar2sqfs/process_tarball.c33
-rw-r--r--include/tar.h7
-rw-r--r--lib/tar/pax_header.c4
-rw-r--r--lib/tar/read_header.c40
-rw-r--r--tests/libtar/tar_big_file.c9
-rw-r--r--tests/libtar/tar_fuzz.c2
-rw-r--r--tests/libtar/tar_simple.c15
-rw-r--r--tests/libtar/tar_sparse.c7
-rw-r--r--tests/libtar/tar_sparse_gnu.c7
-rw-r--r--tests/libtar/tar_target_filled.c24
-rw-r--r--tests/libtar/tar_xattr.c9
-rw-r--r--tests/libtar/tar_xattr_bin.c9
12 files changed, 74 insertions, 92 deletions
diff --git a/bin/tar2sqfs/process_tarball.c b/bin/tar2sqfs/process_tarball.c
index 8465760..c0ae5a3 100644
--- a/bin/tar2sqfs/process_tarball.c
+++ b/bin/tar2sqfs/process_tarball.c
@@ -128,6 +128,7 @@ static int create_node_and_repack_data(istream_t *input_file,
tar_header_decoded_t *hdr)
{
tree_node_t *node;
+ struct stat sb;
if (hdr->is_hard_link) {
node = fstree_add_hard_link(&sqfs->fs, hdr->name,
@@ -143,11 +144,19 @@ static int create_node_and_repack_data(istream_t *input_file,
}
if (!keep_time) {
- hdr->sb.st_mtime = sqfs->fs.defaults.st_mtime;
+ hdr->mtime = sqfs->fs.defaults.st_mtime;
}
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = hdr->mode;
+ sb.st_uid = hdr->uid;
+ sb.st_gid = hdr->gid;
+ sb.st_rdev = hdr->devno;
+ sb.st_size = hdr->actual_size;
+ sb.st_mtime = hdr->mtime;
+
node = fstree_add_generic(&sqfs->fs, hdr->name,
- &hdr->sb, hdr->link_target);
+ &sb, hdr->link_target);
if (node == NULL)
goto fail_errno;
@@ -159,9 +168,9 @@ static int create_node_and_repack_data(istream_t *input_file,
return -1;
}
- if (S_ISREG(hdr->sb.st_mode)) {
+ if (S_ISREG(hdr->mode)) {
if (write_file(input_file, sqfs, hdr, &node->data.file,
- hdr->sb.st_size)) {
+ hdr->actual_size)) {
return -1;
}
}
@@ -175,17 +184,17 @@ fail_errno:
static int set_root_attribs(sqfs_writer_t *sqfs,
const tar_header_decoded_t *hdr)
{
- if (hdr->is_hard_link || !S_ISDIR(hdr->sb.st_mode)) {
+ if (hdr->is_hard_link || !S_ISDIR(hdr->mode)) {
fprintf(stderr, "'%s' is not a directory!\n", hdr->name);
return -1;
}
- sqfs->fs.root->uid = hdr->sb.st_uid;
- sqfs->fs.root->gid = hdr->sb.st_gid;
- sqfs->fs.root->mode = hdr->sb.st_mode;
+ sqfs->fs.root->uid = hdr->uid;
+ sqfs->fs.root->gid = hdr->gid;
+ sqfs->fs.root->mode = hdr->mode;
if (keep_time)
- sqfs->fs.root->mod_time = hdr->sb.st_mtime;
+ sqfs->fs.root->mod_time = hdr->mtime;
if (!cfg.no_xattr) {
if (copy_xattr(sqfs, sqfs->fs.root, hdr))
@@ -220,8 +229,6 @@ int process_tarball(istream_t *input_file, sqfs_writer_t *sqfs)
if ((sqfs_u64)hdr.mtime > 0x0FFFFFFFFUL)
hdr.mtime = 0x0FFFFFFFFUL;
- hdr.sb.st_mtime = hdr.mtime;
-
skip = false;
is_root = false;
is_prefixed = true;
@@ -276,7 +283,7 @@ int process_tarball(istream_t *input_file, sqfs_writer_t *sqfs)
}
if (!is_prefixed) {
- if (skip_entry(input_file, hdr.sb.st_size))
+ if (skip_entry(input_file, hdr.record_size))
goto fail;
clear_header(&hdr);
continue;
@@ -319,7 +326,7 @@ int process_tarball(istream_t *input_file, sqfs_writer_t *sqfs)
if (skip) {
if (dont_skip)
goto fail;
- if (skip_entry(input_file, hdr.sb.st_size))
+ if (skip_entry(input_file, hdr.record_size))
goto fail;
clear_header(&hdr);
diff --git a/include/tar.h b/include/tar.h
index 10e7b52..41be57f 100644
--- a/include/tar.h
+++ b/include/tar.h
@@ -78,7 +78,6 @@ typedef struct tar_xattr_t {
} tar_xattr_t;
typedef struct {
- struct stat sb;
char *name;
char *link_target;
sparse_map_t *sparse;
@@ -88,8 +87,10 @@ typedef struct {
bool is_hard_link;
tar_xattr_t *xattr;
- /* broken out since struct stat could contain
- 32 bit values on 32 bit systems. */
+ sqfs_u16 mode;
+ sqfs_u64 uid;
+ sqfs_u64 gid;
+ sqfs_u64 devno;
sqfs_s64 mtime;
} tar_header_decoded_t;
diff --git a/lib/tar/pax_header.c b/lib/tar/pax_header.c
index 71b849b..d24def0 100644
--- a/lib/tar/pax_header.c
+++ b/lib/tar/pax_header.c
@@ -10,13 +10,13 @@
static int pax_uid(tar_header_decoded_t *out, sqfs_u64 id)
{
- out->sb.st_uid = id;
+ out->uid = id;
return 0;
}
static int pax_gid(tar_header_decoded_t *out, sqfs_u64 id)
{
- out->sb.st_gid = id;
+ out->gid = id;
return 0;
}
diff --git a/lib/tar/read_header.c b/lib/tar/read_header.c
index ecba0bc..d1790de 100644
--- a/lib/tar/read_header.c
+++ b/lib/tar/read_header.c
@@ -74,27 +74,27 @@ static int decode_header(const tar_header_t *hdr, unsigned int set_by_pax,
if (!(set_by_pax & PAX_UID)) {
if (read_number(hdr->uid, sizeof(hdr->uid), &field))
return -1;
- out->sb.st_uid = field;
+ out->uid = field;
}
if (!(set_by_pax & PAX_GID)) {
if (read_number(hdr->gid, sizeof(hdr->gid), &field))
return -1;
- out->sb.st_gid = field;
+ out->gid = field;
}
if (!(set_by_pax & PAX_DEV_MAJ)) {
if (read_number(hdr->devmajor, sizeof(hdr->devmajor), &field))
return -1;
- out->sb.st_rdev = makedev(field, minor(out->sb.st_rdev));
+ out->devno = makedev(field, minor(out->devno));
}
if (!(set_by_pax & PAX_DEV_MIN)) {
if (read_number(hdr->devminor, sizeof(hdr->devminor), &field))
return -1;
- out->sb.st_rdev = makedev(major(out->sb.st_rdev), field);
+ out->devno = makedev(major(out->devno), field);
}
if (!(set_by_pax & PAX_MTIME)) {
@@ -111,7 +111,7 @@ static int decode_header(const tar_header_t *hdr, unsigned int set_by_pax,
if (read_octal(hdr->mode, sizeof(hdr->mode), &field))
return -1;
- out->sb.st_mode = field & 07777;
+ out->mode = field & 07777;
if (hdr->typeflag == TAR_TYPE_LINK ||
hdr->typeflag == TAR_TYPE_SLINK) {
@@ -131,42 +131,31 @@ static int decode_header(const tar_header_t *hdr, unsigned int set_by_pax,
case '\0':
case TAR_TYPE_FILE:
case TAR_TYPE_GNU_SPARSE:
- out->sb.st_mode |= S_IFREG;
+ out->mode |= S_IFREG;
break;
case TAR_TYPE_LINK:
out->is_hard_link = true;
break;
case TAR_TYPE_SLINK:
- out->sb.st_mode = S_IFLNK | 0777;
+ out->mode = S_IFLNK | 0777;
break;
case TAR_TYPE_CHARDEV:
- out->sb.st_mode |= S_IFCHR;
+ out->mode |= S_IFCHR;
break;
case TAR_TYPE_BLOCKDEV:
- out->sb.st_mode |= S_IFBLK;
+ out->mode |= S_IFBLK;
break;
case TAR_TYPE_DIR:
- out->sb.st_mode |= S_IFDIR;
+ out->mode |= S_IFDIR;
break;
case TAR_TYPE_FIFO:
- out->sb.st_mode |= S_IFIFO;
+ out->mode |= S_IFIFO;
break;
default:
out->unknown_record = true;
break;
}
- if (sizeof(time_t) * CHAR_BIT < 64) {
- if (out->mtime > (sqfs_s64)INT32_MAX) {
- out->sb.st_mtime = INT32_MAX;
- } else if (out->mtime < (sqfs_s64)INT32_MIN) {
- out->sb.st_mtime = INT32_MIN;
- } else {
- out->sb.st_mtime = out->mtime;
- }
- } else {
- out->sb.st_mtime = out->mtime;
- }
return 0;
}
@@ -268,12 +257,9 @@ int read_header(istream_t *fp, tar_header_decoded_t *out)
goto fail;
}
- if (out->sparse != NULL) {
- out->sb.st_size = out->actual_size;
- } else {
- out->sb.st_size = out->record_size;
+ if (out->sparse == NULL)
out->actual_size = out->record_size;
- }
+
return 0;
out_eof:
clear_header(out);
diff --git a/tests/libtar/tar_big_file.c b/tests/libtar/tar_big_file.c
index abea1ef..499805f 100644
--- a/tests/libtar/tar_big_file.c
+++ b/tests/libtar/tar_big_file.c
@@ -17,11 +17,10 @@ int main(int argc, char **argv)
fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 8589934592);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542959190);
+ TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.uid, 01750);
+ TEST_EQUAL_UI(hdr.gid, 01750);
+ TEST_EQUAL_UI(hdr.actual_size, 8589934592);
TEST_EQUAL_UI(hdr.mtime, 1542959190);
TEST_STR_EQUAL(hdr.name, "big-file.bin");
TEST_ASSERT(!hdr.unknown_record);
diff --git a/tests/libtar/tar_fuzz.c b/tests/libtar/tar_fuzz.c
index e5f5c0b..d5728b5 100644
--- a/tests/libtar/tar_fuzz.c
+++ b/tests/libtar/tar_fuzz.c
@@ -33,7 +33,7 @@ int main(int argc, char **argv)
if (ret < 0)
goto fail;
- ret = istream_skip(fp, hdr.sb.st_size);
+ ret = istream_skip(fp, hdr.record_size);
clear_header(&hdr);
if (ret < 0)
diff --git a/tests/libtar/tar_simple.c b/tests/libtar/tar_simple.c
index 54b06c8..e5f0137 100644
--- a/tests/libtar/tar_simple.c
+++ b/tests/libtar/tar_simple.c
@@ -44,19 +44,12 @@ int main(int argc, char **argv)
fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, TESTUID);
- TEST_EQUAL_UI(hdr.sb.st_gid, TESTGID);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
+ TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.uid, TESTUID);
+ TEST_EQUAL_UI(hdr.gid, TESTGID);
+ TEST_EQUAL_UI(hdr.actual_size, 5);
ts = TESTTS;
-
- if (sizeof(time_t) < sizeof(ts) && ts > INT32_MAX) {
- TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
- } else {
- TEST_EQUAL_UI(hdr.sb.st_mtime, ts);
- }
-
TEST_EQUAL_UI(hdr.mtime, ts);
TEST_STR_EQUAL(hdr.name, fname);
TEST_ASSERT(!hdr.unknown_record);
diff --git a/tests/libtar/tar_sparse.c b/tests/libtar/tar_sparse.c
index c4313f0..24f7a57 100644
--- a/tests/libtar/tar_sparse.c
+++ b/tests/libtar/tar_sparse.c
@@ -17,10 +17,9 @@ static void test_case_sparse(const char *path)
fp = istream_open_file(path);
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 2097152);
+ TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.uid, 01750);
+ TEST_EQUAL_UI(hdr.gid, 01750);
TEST_EQUAL_UI(hdr.actual_size, 2097152);
TEST_EQUAL_UI(hdr.record_size, 32768);
TEST_STR_EQUAL(hdr.name, "input.bin");
diff --git a/tests/libtar/tar_sparse_gnu.c b/tests/libtar/tar_sparse_gnu.c
index 06f79f1..5d12478 100644
--- a/tests/libtar/tar_sparse_gnu.c
+++ b/tests/libtar/tar_sparse_gnu.c
@@ -20,10 +20,9 @@ int main(int argc, char **argv)
fp = istream_open_file("sparse-files/gnu-small.tar");
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 524288);
+ TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.uid, 01750);
+ TEST_EQUAL_UI(hdr.gid, 01750);
TEST_EQUAL_UI(hdr.actual_size, 524288);
TEST_EQUAL_UI(hdr.record_size, 8192);
TEST_STR_EQUAL(hdr.name, "input.bin");
diff --git a/tests/libtar/tar_target_filled.c b/tests/libtar/tar_target_filled.c
index f0f4026..57c6af9 100644
--- a/tests/libtar/tar_target_filled.c
+++ b/tests/libtar/tar_target_filled.c
@@ -22,33 +22,33 @@ int main(int argc, char **argv)
/* "deep" directory hierarchy containg 2 files */
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777);
TEST_STR_EQUAL(hdr.name, "20_characters_here01/");
clear_header(&hdr);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777);
TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/");
clear_header(&hdr);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777);
TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/"
"20_characters_here03/");
clear_header(&hdr);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777);
TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/"
"20_characters_here03/20_characters_here04/");
clear_header(&hdr);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFREG | 0777);
TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/"
"20_characters_here03/20_characters_here04/"
"errored_file_tst");
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
+ TEST_EQUAL_UI(hdr.actual_size, 5);
TEST_ASSERT(istream_read(fp, buffer, 5) == 5);
buffer[5] = '\0';
TEST_STR_EQUAL(buffer, "test\n");
@@ -56,11 +56,11 @@ int main(int argc, char **argv)
clear_header(&hdr);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFREG | 0777);
TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/"
"20_characters_here03/20_characters_here04/"
"some_test_file");
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
+ TEST_EQUAL_UI(hdr.actual_size, 5);
TEST_ASSERT(istream_read(fp, buffer, 5) == 5);
buffer[5] = '\0';
TEST_STR_EQUAL(buffer, "test\n");
@@ -69,23 +69,23 @@ int main(int argc, char **argv)
/* "deep" directory hierarchy containg a hard link */
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777);
TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/");
clear_header(&hdr);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777);
TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/");
clear_header(&hdr);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777);
TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/"
"20CharsForLnkTest003/");
clear_header(&hdr);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777);
+ TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777);
TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/"
"20CharsForLnkTest003/20CharsForLnkTest004/");
clear_header(&hdr);
diff --git a/tests/libtar/tar_xattr.c b/tests/libtar/tar_xattr.c
index 633c3a2..877bfba 100644
--- a/tests/libtar/tar_xattr.c
+++ b/tests/libtar/tar_xattr.c
@@ -18,11 +18,10 @@ int main(int argc, char **argv)
fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477);
+ TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.uid, 01750);
+ TEST_EQUAL_UI(hdr.gid, 01750);
+ TEST_EQUAL_UI(hdr.actual_size, 5);
TEST_EQUAL_UI(hdr.mtime, 1543094477);
TEST_STR_EQUAL(hdr.name, "input.txt");
TEST_ASSERT(!hdr.unknown_record);
diff --git a/tests/libtar/tar_xattr_bin.c b/tests/libtar/tar_xattr_bin.c
index f44e26f..51ca0b0 100644
--- a/tests/libtar/tar_xattr_bin.c
+++ b/tests/libtar/tar_xattr_bin.c
@@ -26,11 +26,10 @@ int main(int argc, char **argv)
fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477);
+ TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.uid, 01750);
+ TEST_EQUAL_UI(hdr.gid, 01750);
+ TEST_EQUAL_UI(hdr.actual_size, 5);
TEST_EQUAL_UI(hdr.mtime, 1543094477);
TEST_STR_EQUAL(hdr.name, "input.txt");
TEST_ASSERT(!hdr.unknown_record);