From 57b5f9d671b718e0b07a96903ed0f2ba71e45d33 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Tue, 9 Apr 2013 16:24:41 +0300 Subject: [PATCH] gpt_parser: validate GPT header revision We only support revision 1.0. Change-Id: If44c27053186e77329681bdda387dc0f6d92c893 Signed-off-by: Artem Bityutskiy --- mic/utils/gpt_parser.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mic/utils/gpt_parser.py b/mic/utils/gpt_parser.py index 425f4a8..7cf61e5 100644 --- a/mic/utils/gpt_parser.py +++ b/mic/utils/gpt_parser.py @@ -20,10 +20,12 @@ GPT header and the GPT partition table. """ import struct import uuid +import binascii from mic.utils.errors import MountError -_GPT_HEADER_FORMAT = "<8sIIIIQQQQ16sQIII420x" +_GPT_HEADER_FORMAT = "<8s4sIIIQQQQ16sQIII420x" _GPT_ENTRY_FORMAT = "<16s16sQQQ72s" +_SUPPORTED_GPT_REVISION = '\x00\x00\x01\x00' def _stringify_uuid(binary_uuid): """ A small helper function to transform a binary UUID into a string @@ -80,11 +82,18 @@ class GptParser: header = struct.unpack(_GPT_HEADER_FORMAT, header) - # Perform a simple validation + # Validate the signature if header[0] != 'EFI PART': raise MountError("GPT paritition table on disk '%s' not found" % \ self.disk_path) + # Validate the revision + if header[1] != _SUPPORTED_GPT_REVISION: + raise MountError("Unsupported GPT revision '%s', supported " \ + "revision is '%s'" % \ + (binascii.hexlify(header[1]), + binascii.hexlify(_SUPPORTED_GPT_REVISION))) + return (header[0], # 0. Signature header[1], # 1. Revision header[2], # 2. Header size in bytes -- 2.7.4