From: Karel Zak Date: Wed, 21 Nov 2012 14:47:56 +0000 (+0100) Subject: libblkid: (gpt) don't modify in memory buffers X-Git-Tag: v2.23-rc1~511 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f907d66b6346f80ff4d6289eedd46741efa6f415;p=thirdparty%2Futil-linux.git libblkid: (gpt) don't modify in memory buffers LIBBLKID_DEBUG=0xffff blkid -p .... gpt: ---> call probefunc() reuse buffer: off=0 len=1024 pr=0xb0b690 reuse buffer: off=0 len=1024 pr=0xb0b690 reuse buffer: off=1024 len=16384 pr=0xb0b690 GPT entries corrupted reuse buffer: off=10737417728 len=512 pr=0xb0b690 reuse buffer: off=10737401344 len=16384 pr=0xb0b690 GPT entries corrupted gpt: <--- (rc = 1) Reported-by: Dave Reisner Signed-off-by: Karel Zak --- diff --git a/libblkid/src/partitions/gpt.c b/libblkid/src/partitions/gpt.c index ccade6b54e..98e82bfd2f 100644 --- a/libblkid/src/partitions/gpt.c +++ b/libblkid/src/partitions/gpt.c @@ -226,15 +226,15 @@ static struct gpt_header *get_gpt_header( return NULL; /* Header has to be verified when header_crc32 is zero */ - orgcrc = le32_to_cpu(h->header_crc32); + orgcrc = h->header_crc32; h->header_crc32 = 0; - crc = count_crc32((unsigned char *) h, hsz); - if (crc != orgcrc) { + h->header_crc32 = orgcrc; + + if (crc != le32_to_cpu(orgcrc)) { DBG(DEBUG_LOWPROBE, printf("GPT header corrupted\n")); return NULL; } - h->header_crc32 = cpu_to_le32(orgcrc); /* Valid header has to be at MyLBA */ if (le64_to_cpu(h->my_lba) != lba) { @@ -300,7 +300,7 @@ static int probe_gpt_pt(blkid_probe pr, blkid_partlist ls; uint64_t fu, lu; uint32_t ssf, i; - + efi_guid_t guid; if (last_lba(pr, &lastlba)) goto nothing; @@ -369,14 +369,13 @@ static int probe_gpt_pt(blkid_probe pr, (unsigned char *) e->partition_name, sizeof(e->partition_name), BLKID_ENC_UTF16LE); - swap_efi_guid(&e->unique_partition_guid); - swap_efi_guid(&e->partition_type_guid); - - blkid_partition_set_uuid(par, - (const unsigned char *) &e->unique_partition_guid); + guid = e->unique_partition_guid; + swap_efi_guid(&guid); + blkid_partition_set_uuid(par, (const unsigned char *) &guid); - blkid_partition_set_type_uuid(par, - (const unsigned char *) &e->partition_type_guid); + guid = e->partition_type_guid; + swap_efi_guid(&guid); + blkid_partition_set_type_uuid(par, (const unsigned char *) &guid); blkid_partition_set_flags(par, e->attributes); }