summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@intel.com>2013-04-09 16:24:41 +0300
committerArtem Bityutskiy <artem.bityutskiy@intel.com>2013-04-19 16:03:53 +0300
commit57b5f9d671b718e0b07a96903ed0f2ba71e45d33 (patch)
treec102cdc4f598ae16aac2a90b21a200613f1840ad
parent68a2c4f24b20f895f83a47823a396b97911753a4 (diff)
downloadmic-57b5f9d671b718e0b07a96903ed0f2ba71e45d33.tar.gz
mic-57b5f9d671b718e0b07a96903ed0f2ba71e45d33.tar.bz2
mic-57b5f9d671b718e0b07a96903ed0f2ba71e45d33.zip
gpt_parser: validate GPT header revision
We only support revision 1.0. Change-Id: If44c27053186e77329681bdda387dc0f6d92c893 Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
-rw-r--r--mic/utils/gpt_parser.py13
1 files 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