Check the correct length of the GPT header signature

The length of the signature is 8 bytes. We've been checking 9
bytes instead, pretty much forever. All the tests have passed
because although the signature we're looking for is an 8-byte
string followed by a '\0', the next field in the header contains
the revision number 0x00010000, so the 9th byte is always zero.

We should follow the spec, though.

BUG=none
BRANCH=none
TEST=make runtests

Change-Id: I7cc6370250fa36a193f4a9fa5bc0099aea465618
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/247331
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Bill Richardson
2015-02-06 15:35:34 -08:00
committed by ChromeOS Commit Bot
parent b550fb1804
commit 864fae2d78

View File

@@ -2,19 +2,22 @@
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
* Defines EFI related structure. See more details in EFI 2.3 spec. * Defines UEFI related structure. See more details in the UEFI spec.
* *
* To download EFI standard, please visit UEFI homepage: * To download UEFI standard, please visit UEFI homepage:
* http://www.uefi.org/ * http://www.uefi.org/
*/ */
#ifndef VBOOT_REFERENCE_CGPTLIB_GPT_H_ #ifndef VBOOT_REFERENCE_CGPTLIB_GPT_H_
#define VBOOT_REFERENCE_CGPTLIB_GPT_H_ #define VBOOT_REFERENCE_CGPTLIB_GPT_H_
#include <stdint.h> #include <stdint.h>
#define GPT_HEADER_SIGNATURE "EFI PART" /* From the specification */
#define GPT_HEADER_SIGNATURE2 "CHROMEOS" #define GPT_HEADER_SIGNATURE_SIZE 8
#define GPT_HEADER_SIGNATURE_SIZE sizeof(GPT_HEADER_SIGNATURE)
#define GPT_HEADER_REVISION 0x00010000 #define GPT_HEADER_REVISION 0x00010000
#define GPT_HEADER_SIGNATURE "EFI PART"
/* From https://chromium-review.googlesource.com/31264 */
#define GPT_HEADER_SIGNATURE2 "CHROMEOS"
/* /*
* The first 3 numbers should be stored in network-endian format according to * The first 3 numbers should be stored in network-endian format according to
@@ -43,7 +46,7 @@
#define UUID_NODE_LEN 6 #define UUID_NODE_LEN 6
#define GUID_SIZE 16 #define GUID_SIZE 16
/* GUID definition. Defined in appendix A of EFI standard. */ /* GUID definition. Defined in appendix A of UEFI standard. */
typedef struct { typedef struct {
union { union {
struct { struct {
@@ -63,12 +66,12 @@ typedef struct {
/* /*
* GPT header defines how many partitions exist on a drive and sectors managed. * GPT header defines how many partitions exist on a drive and sectors managed.
* For every drive device, there are 2 headers, primary and secondary. Most of * For every drive device, there are 2 headers, primary and secondary. Most of
* fields are duplicated except my_lba and entries_lba. * the fields are duplicates except my_lba and entries_lba.
* *
* You may find more details in chapter 5 of EFI standard. * You may find more details in chapter 5 of the UEFI standard.
*/ */
typedef struct { typedef struct {
char signature[8]; char signature[GPT_HEADER_SIGNATURE_SIZE];
uint32_t revision; uint32_t revision;
uint32_t size; uint32_t size;
uint32_t header_crc32; uint32_t header_crc32;
@@ -91,7 +94,7 @@ typedef struct {
* GPT partition entry defines the starting and ending LBAs of a partition. It * GPT partition entry defines the starting and ending LBAs of a partition. It
* also contains the unique GUID, type, and attribute bits. * also contains the unique GUID, type, and attribute bits.
* *
* You may find more details in chapter 5 of EFI standard. * You may find more details in chapter 5 of the UEFI standard.
*/ */
typedef struct { typedef struct {
Guid type; Guid type;