-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No functional change. The large number of partitions in the test is to ensure that the code correctly handles such partition tables without a buffer overflow. Previous versions of the code did have a buffer overflow due to incorrectly computing the buffer size.
- Loading branch information
Showing
5 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
label: gpt | ||
label-id: F4796A2A-E377-45BD-B539-D6D49E569055 | ||
device: /dev/loop0 | ||
unit: sectors | ||
first-lba: 24 | ||
sector-size: 512 | ||
table-length: 33 | ||
last-lba: 41943029 | ||
|
||
/dev/loop0p1 : start=32, size=409592, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=FA4D6529-56DA-47C7-AE88-E2DFECB72621, name="EFI System" | ||
/dev/loop0p2 : start=411648, size= 4096, type=21686148-6449-6E6F-744E-656564454649, uuid=1E6C9DB4-1E91-46C4-846A-2030DCB13B8C, name="BIOS boot partition" | ||
/dev/loop0p3 : start=415744, size= 4096, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=5DCECC9F-71B8-4357-8039-1BEBB7A48653, name="/home" | ||
/dev/loop0p4 : start=419840, size= 4096, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=3EA4A03F-ACCF-4EDF-99EC-8E5F2B382459, name="/usr" | ||
/dev/loop0p5 : start=423944,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p6 : start=423952,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p7 : start=423960,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p8 : start=423968,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p9 : start=423976,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p10 : start=423984,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p11 : start=423992,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p12 : start=424000,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p13 : start=424008,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p14 : start=424016,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p15 : start=424024,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p16 : start=424032,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p17 : start=424040,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p18 : start=424048,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p19 : start=424056,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p20 : start=424064,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p21 : start=424072,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p22 : start=424080,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p23 : start=424088,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p24 : start=424096,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p25 : start=424104,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p26 : start=424112,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p27 : start=424120,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p28 : start=424128,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p29 : start=424136,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p30 : start=424144,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p31 : start=424152,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p32 : start=424160,size=8, type=00000000-0000-0000-0000-000000000000,uuid=00000000-0000-0000-0000-000000000000,name="" | ||
/dev/loop0p33 : start=424168,size=41518848,type=0FC63DAF-8483-4772-8E79-3D69D8477DE4,uuid=693244E6-3E07-47BF-AD79-ACADE4293FE7,name="Root filesystem" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash -- | ||
set -euo pipefail | ||
|
||
case $0 in (/*) cd "${0%/*}/";; (*/*) cd "./${0%/*}";; (*) :;; esac | ||
make -C .. gptfixer/gpt | ||
chk () { | ||
loopdev=$(sudo losetup --nooverlap --find --sector-size "$1" --show -- dummy.img) | ||
if [[ "$loopdev" != '/dev/loop0' ]]; then | ||
printf 'Loop device is not /dev/loop0 (got %q), expect test failure\n' "$loopdev" | ||
fi >&3 | ||
echo Dumping broken partition table | ||
sudo sfdisk --label=gpt --dump -- "$loopdev" | ||
sudo ./gpt fix "$loopdev" | ||
echo Dumping fixed partition table | ||
sudo sfdisk --label=gpt --dump -- "$loopdev" | ||
sudo losetup -d "$loopdev" | ||
} | ||
|
||
go () ( | ||
set -x | ||
truncate -s 0 dummy.img | ||
truncate -s 20GiB dummy.img | ||
sfdisk --force dummy.img < layout | ||
chk 4096 | ||
chk 512 | ||
) | ||
|
||
case "$#,${1-}" in | ||
('1,update') go 3>&2 > test.sh.stdout 2> test.sh.stderr;; | ||
(0,) | ||
tmpdir=$(mktemp -d) | ||
go 3>&2 > "$tmpdir/stdout" 2> "$tmpdir/stderr" | ||
diff -u -- "$tmpdir/stdout" test.sh.stdout | ||
diff -u -- "$tmpdir/stderr" test.sh.stderr | ||
rm -rf -- "$tmpdir" | ||
;; | ||
(*) echo "Usage: test.sh [update]" >&2; exit 1;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
+ truncate -s 0 dummy.img | ||
+ truncate -s 20GiB dummy.img | ||
+ sfdisk --force dummy.img | ||
+ chk 4096 | ||
++ sudo losetup --nooverlap --find --sector-size 4096 --show -- dummy.img | ||
+ loopdev=/dev/loop0 | ||
+ [[ /dev/loop0 != \/\d\e\v\/\l\o\o\p\0 ]] | ||
+ echo Dumping broken partition table | ||
+ sudo sfdisk --label=gpt --dump -- /dev/loop0 | ||
GPT PMBR size mismatch (41943039 != 5242879) will be corrected by write. | ||
+ sudo ./gpt fix /dev/loop0 | ||
gpt: Found GPT with different sector size, altering | ||
+ echo Dumping fixed partition table | ||
+ sudo sfdisk --label=gpt --dump -- /dev/loop0 | ||
+ sudo losetup -d /dev/loop0 | ||
+ chk 512 | ||
++ sudo losetup --nooverlap --find --sector-size 512 --show -- dummy.img | ||
+ loopdev=/dev/loop0 | ||
+ [[ /dev/loop0 != \/\d\e\v\/\l\o\o\p\0 ]] | ||
+ echo Dumping broken partition table | ||
+ sudo sfdisk --label=gpt --dump -- /dev/loop0 | ||
GPT PMBR size mismatch (5242879 != 41943039) will be corrected by write. | ||
+ sudo ./gpt fix /dev/loop0 | ||
gpt: Found GPT with different sector size, altering | ||
+ echo Dumping fixed partition table | ||
+ sudo sfdisk --label=gpt --dump -- /dev/loop0 | ||
+ sudo losetup -d /dev/loop0 |
Oops, something went wrong.