diff options
author | kientzle <kientzle@FreeBSD.org> | 2008-08-22 02:09:10 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2008-08-22 02:09:10 +0000 |
commit | 6ab64e14fc373a159372cb6b7df2bf63d117b6f2 (patch) | |
tree | 5e4b48f5ccc4aa7fb44cf48f0497bc619142119c /usr.bin/cpio | |
parent | 1168b06701c6ce7b123a2ee833738c2d381366fa (diff) | |
download | FreeBSD-src-6ab64e14fc373a159372cb6b7df2bf63d117b6f2.zip FreeBSD-src-6ab64e14fc373a159372cb6b7df2bf63d117b6f2.tar.gz |
The newc-format verification is now a little smarter about
following the archive structure. In particular, it no longer
crashes if you run it against GNU cpio 2.9 (although it does
still complain a lot more than it should).
Diffstat (limited to 'usr.bin/cpio')
-rw-r--r-- | usr.bin/cpio/test/test_format_newc.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/usr.bin/cpio/test/test_format_newc.c b/usr.bin/cpio/test/test_format_newc.c index 0714bd4..9579c88 100644 --- a/usr.bin/cpio/test/test_format_newc.c +++ b/usr.bin/cpio/test/test_format_newc.c @@ -68,7 +68,7 @@ DEFINE_TEST(test_format_newc) int devmajor, devminor, ino, gid; time_t t, t2, now; char *p, *e; - size_t s; + size_t s, fs, ns; mode_t oldmask; oldmask = umask(0); @@ -141,16 +141,21 @@ DEFINE_TEST(test_format_newc) " first appearance should be empty, so this file size\n" " field should be zero"); assertEqualInt(0, from_hex(e + 54, 8)); /* File size */ + fs = from_hex(e + 54, 8); + fs += 3 & -fs; devmajor = from_hex(e + 62, 8); /* devmajor */ devminor = from_hex(e + 70, 8); /* devminor */ assert(is_hex(e + 78, 8)); /* rdevmajor */ assert(is_hex(e + 86, 8)); /* rdevminor */ assertEqualMem(e + 94, "00000006", 8); /* Name size */ + ns = from_hex(e + 94, 8); + ns += 3 & (-ns - 2); assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ assertEqualMem(e + 110, "file1\0", 6); /* Name contents */ /* Since there's another link, no file contents here. */ /* But add in file size so that an error here doesn't cascade. */ - e += 116 + from_hex(e + 54, 8) + (3 & -from_hex(e + 54, 8)); + e += 110 + fs + ns; + /* "symlink" pointing to "file1" */ assert(is_hex(e, 110)); assertEqualMem(e + 0, "070701", 6); /* Magic */ @@ -163,15 +168,19 @@ DEFINE_TEST(test_format_newc) failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ assertEqualMem(e + 54, "00000005", 8); /* File size */ + fs = from_hex(e + 54, 8); + fs += 3 & -fs; assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ assert(is_hex(e + 78, 8)); /* rdevmajor */ assert(is_hex(e + 86, 8)); /* rdevminor */ assertEqualMem(e + 94, "00000008", 8); /* Name size */ + ns = from_hex(e + 94, 8); + ns += 3 & (-ns - 2); assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ assertEqualMem(e + 110, "symlink\0\0\0", 10); /* Name contents */ - assertEqualMem(e + 120, "file1\0\0\0", 8); /* symlink target */ - e += 120 + from_hex(e + 54, 8) + (3 & -from_hex(e + 54, 8)); + assertEqualMem(e + 110 + ns, "file1\0\0\0", 8); /* symlink target */ + e += 110 + fs + ns; /* "dir" */ assert(is_hex(e, 110)); @@ -185,16 +194,18 @@ DEFINE_TEST(test_format_newc) failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ assertEqualMem(e + 54, "00000000", 8); /* File size */ + fs = from_hex(e + 54, 8); + fs += 3 & -fs; assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ assert(is_hex(e + 78, 8)); /* rdevmajor */ assert(is_hex(e + 86, 8)); /* rdevminor */ assertEqualMem(e + 94, "00000004", 8); /* Name size */ + ns = from_hex(e + 94, 8); + ns += 3 & (-ns - 2); assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ assertEqualMem(e + 110, "dir\0\0\0", 6); /* Name contents */ - e += 116; - - /* TODO: Verify other types of entries. */ + e += 110 + fs + ns; /* Hardlink identical to "file1" */ /* Since we only wrote two of the three links to this @@ -211,15 +222,19 @@ DEFINE_TEST(test_format_newc) failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ assertEqualInt(10, from_hex(e + 54, 8)); /* File size */ + fs = from_hex(e + 54, 8); + fs += 3 & -fs; assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ assert(is_hex(e + 78, 8)); /* rdevmajor */ assert(is_hex(e + 86, 8)); /* rdevminor */ assertEqualMem(e + 94, "00000009", 8); /* Name size */ + ns = from_hex(e + 94, 8); + ns += 3 & (-ns - 2); assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ assertEqualMem(e + 110, "hardlink\0\0", 10); /* Name contents */ - assertEqualMem(e + 120, "123456789\0\0\0", 12); /* File contents */ - e += 120 + from_hex(e + 54, 8) + (3 & -from_hex(e + 54, 8)); + assertEqualMem(e + 110 + ns, "123456789\0\0\0", 12); /* File contents */ + e += 110 + ns + fs; /* Last entry is end-of-archive marker. */ assert(is_hex(e, 110)); |