47b8266825
- Fix integer overflows with DVH disk label
153 lines
5.1 KiB
Diff
153 lines
5.1 KiB
Diff
From 248262f5778ab64a0ccb03d3a269feb245f9b844 Mon Sep 17 00:00:00 2001
|
|
From: "Brian C. Lane" <bcl@redhat.com>
|
|
Date: Tue, 8 Apr 2014 17:08:22 -0700
|
|
Subject: [PATCH 92/93] testing: Use little-endian packing in gpt tests
|
|
|
|
Fix gpt-header-move.py and gpt-header-munge to use little endian when
|
|
packing and unpacking. This allows us to turn the t0210 and t0211 tests
|
|
back on for big-endian systems.
|
|
|
|
* tests/gpt-header-move.py: Use little endian for pack/unpack
|
|
* tests/gpt-header-munge: Same
|
|
* tests/t-lib-helpers.sh: Add requires_64bit_ that checks for x86_64 and ppc64
|
|
* tests/t0210-gpt-resized-partition-entry-array.sh: Remove x86_64 test
|
|
* tests/t0211-gpt-rewrite-header.sh: Same
|
|
---
|
|
tests/gpt-header-move.py | 16 ++++++++--------
|
|
tests/gpt-header-munge | 6 +++---
|
|
tests/t-lib-helpers.sh | 12 ++++++++++++
|
|
tests/t0210-gpt-resized-partition-entry-array.sh | 6 ++----
|
|
tests/t0211-gpt-rewrite-header.sh | 6 ++----
|
|
5 files changed, 27 insertions(+), 19 deletions(-)
|
|
|
|
diff --git a/tests/gpt-header-move.py b/tests/gpt-header-move.py
|
|
index 69d1479..977febb 100644
|
|
--- a/tests/gpt-header-move.py
|
|
+++ b/tests/gpt-header-move.py
|
|
@@ -8,14 +8,14 @@ import sys
|
|
file = open(sys.argv[1],'rb+')
|
|
file.seek(512)
|
|
gptheader = file.read(512)
|
|
-altlba = unpack_from('q', gptheader,offset=32)[0]
|
|
+altlba = unpack_from('<q', gptheader,offset=32)[0]
|
|
gptheader = array.array('c',gptheader)
|
|
-pack_into('Q', gptheader, 32, altlba-33)
|
|
+pack_into('<Q', gptheader, 32, altlba-33)
|
|
#zero header crc
|
|
-pack_into('L', gptheader, 16, 0)
|
|
+pack_into('<L', gptheader, 16, 0)
|
|
#compute new crc
|
|
newcrc = ((crc32(buffer(gptheader,0,92))) & 0xFFFFFFFF)
|
|
-pack_into('L', gptheader, 16, newcrc)
|
|
+pack_into('<L', gptheader, 16, newcrc)
|
|
file.seek(512)
|
|
file.write(gptheader)
|
|
file.seek(512*altlba)
|
|
@@ -25,14 +25,14 @@ backup = file.read(512*32)
|
|
altlba -= 33
|
|
gptheader = array.array('c',gptheader)
|
|
#update mylba
|
|
-pack_into('Q', gptheader, 24, altlba)
|
|
+pack_into('<Q', gptheader, 24, altlba)
|
|
#update table lba
|
|
-pack_into('Q', gptheader, 72, altlba-32)
|
|
+pack_into('<Q', gptheader, 72, altlba-32)
|
|
#zero header crc
|
|
-pack_into('L', gptheader, 16, 0)
|
|
+pack_into('<L', gptheader, 16, 0)
|
|
#compute new crc
|
|
newcrc = ((crc32(buffer(gptheader,0,92))) & 0xFFFFFFFF)
|
|
-pack_into('L', gptheader, 16, newcrc)
|
|
+pack_into('<L', gptheader, 16, newcrc)
|
|
file.seek(512*(altlba-32))
|
|
file.write(backup)
|
|
file.write(gptheader)
|
|
diff --git a/tests/gpt-header-munge b/tests/gpt-header-munge
|
|
index e7d3d43..5c0dd80 100755
|
|
--- a/tests/gpt-header-munge
|
|
+++ b/tests/gpt-header-munge
|
|
@@ -107,7 +107,7 @@ sub check_GPT_header ($$$)
|
|
}
|
|
|
|
# Save a copy of the CRC, then zero that field, bytes 16..19:
|
|
- my $orig_crc = unpack ('L', substr ($buf, 16, 4));
|
|
+ my $orig_crc = unpack ('L<', substr ($buf, 16, 4));
|
|
substr ($buf, 16, 4) = "\0" x 4;
|
|
|
|
# Compute CRC32 of header: it'd better match.
|
|
@@ -133,7 +133,7 @@ sub set_CRCs ($$$$)
|
|
|
|
# Compute CRC of primary partition array and put it in substr ($pri, 88, 4)
|
|
my $pa_crc = partition_array_crc $pri_or_backup, $n_pe, $in;
|
|
- substr ($$buf, 88, 4) = pack ('L', $pa_crc);
|
|
+ substr ($$buf, 88, 4) = pack ('L<', $pa_crc);
|
|
|
|
# In the backup header, we must also set the 8-byte "Partition entries
|
|
# starting LBA number" field to reflect our new value of $n_pe.
|
|
@@ -151,7 +151,7 @@ sub set_CRCs ($$$$)
|
|
# slot into which we'll store the result.
|
|
substr ($$buf, 16, 4) = "\0" x 4;
|
|
my $crc = crc32($$buf);
|
|
- substr ($$buf, 16, 4) = pack ('L', $crc);
|
|
+ substr ($$buf, 16, 4) = pack ('L<', $crc);
|
|
}
|
|
|
|
sub usage ($)
|
|
diff --git a/tests/t-lib-helpers.sh b/tests/t-lib-helpers.sh
|
|
index 6721003..4e83a05 100644
|
|
--- a/tests/t-lib-helpers.sh
|
|
+++ b/tests/t-lib-helpers.sh
|
|
@@ -398,3 +398,15 @@ device_mapper_required_()
|
|
. "$abs_top_srcdir/tests/t-lvm.sh"
|
|
lvm_init_root_dir_ || fail_ "device mapper setup failed"
|
|
}
|
|
+
|
|
+# Require a 64bit system
|
|
+require_64bit_()
|
|
+{
|
|
+ case $(uname -m) in
|
|
+ x86_64|ppc64)
|
|
+ return 0;;
|
|
+ *)
|
|
+ skip_ "This test requires a 64 bit system"
|
|
+ ;;
|
|
+ esac
|
|
+}
|
|
diff --git a/tests/t0210-gpt-resized-partition-entry-array.sh b/tests/t0210-gpt-resized-partition-entry-array.sh
|
|
index 512f342..86fb8ce 100755
|
|
--- a/tests/t0210-gpt-resized-partition-entry-array.sh
|
|
+++ b/tests/t0210-gpt-resized-partition-entry-array.sh
|
|
@@ -19,10 +19,8 @@
|
|
. "${srcdir=.}/init.sh"; path_prepend_ ../parted $srcdir
|
|
require_perl_digest_crc_
|
|
|
|
-# gpt-header-munge will fail on big-endian systems
|
|
-if test $(uname -m) != x86_64; then
|
|
- skip_ 'this test only works on little-endian systems'
|
|
-fi
|
|
+# gpt-header-munge won't work on 32bit systems
|
|
+require_64bit_
|
|
|
|
ss=$sector_size_
|
|
|
|
diff --git a/tests/t0211-gpt-rewrite-header.sh b/tests/t0211-gpt-rewrite-header.sh
|
|
index a87e753..ee33e43 100644
|
|
--- a/tests/t0211-gpt-rewrite-header.sh
|
|
+++ b/tests/t0211-gpt-rewrite-header.sh
|
|
@@ -23,10 +23,8 @@
|
|
. "${srcdir=.}/init.sh"; path_prepend_ ../parted $srcdir
|
|
require_perl_digest_crc_
|
|
|
|
-# gpt-header-munge will fail on big-endian systems
|
|
-if test $(uname -m) != x86_64; then
|
|
- skip_ 'this test only works on little-endian systems'
|
|
-fi
|
|
+# gpt-header-munge won't work on 32bit systems
|
|
+require_64bit_
|
|
|
|
ss=$sector_size_
|
|
|
|
--
|
|
1.9.0
|
|
|