OSDN Git Service

gpt: don't abort for a truncated GPT-formatted device
authorJim Meyering <meyering@redhat.com>
Fri, 24 Jun 2011 11:32:33 +0000 (13:32 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 24 Jun 2011 14:28:32 +0000 (16:28 +0200)
commit99f9c6a99b5d702a2c42cbce0fb74d09d88b2b0d
treef0c80465480d883c1b8ce2d9ce955af6b5af52d3
parentc1462c42f571f9fb7ba1351b0c4c84ac8cf564b5
gpt: don't abort for a truncated GPT-formatted device

This fixes the problem two ways.  The first fix (via gpt_alloc)
rejects any device that is too small, but it is insufficient.
Choose a slightly larger truncated device with an otherwise intact
primary GPT header and you can still trigger the failed assertion.
To fix it in general, we make _header_is_valid detect the problem.
* libparted/labels/gpt.c (gpt_alloc): Reject a device that is so
small that there is no room for a single partition.
(_header_is_valid): Validate LastUsableLBA here, as well, so that
we now reject as invalid any GPT header that specifies a
LastUsableLBA larger than the device size.
Leave the assertion in _parse_header.
* tests/t0203-gpt-tiny-device-abort.sh: Test for this.
* tests/Makefile.am (TESTS): Add it.
* NEWS: (Bug fixes): Mention it.
Reported by Daniel Fandrich in
http://thread.gmane.org/gmane.comp.gnu.parted.bugs/10466
NEWS
libparted/labels/gpt.c
tests/Makefile.am
tests/t0203-gpt-tiny-device-abort.sh [new file with mode: 0644]