mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Check for valid IOS & IOU image paths and files (by analyzing the firt 7
bytes of their ELF header).
This commit is contained in:
parent
28ca12367a
commit
85336e0fca
@ -271,6 +271,20 @@ class Router(object):
|
||||
self.resume()
|
||||
else:
|
||||
|
||||
if not os.path.isfile(self._image):
|
||||
raise DynamipsError("IOS image '{}' is not accessible".format(self._image))
|
||||
|
||||
try:
|
||||
with open(self._image, "rb") as f:
|
||||
# read the first 7 bytes of the file.
|
||||
elf_header_start = f.read(7)
|
||||
except OSError as e:
|
||||
raise DynamipsError("Cannot read ELF header for IOS image {}: {}".format(self._image, e))
|
||||
|
||||
# IOS images must start with the ELF magic number, be 32-bit, big endian and have an ELF version of 1
|
||||
if elf_header_start != b'\x7fELF\x01\x02\x01':
|
||||
raise DynamipsError("'{}' is not a valid IOU image".format(self._image))
|
||||
|
||||
if self.console and self.aux:
|
||||
# check that console and aux ports are available
|
||||
try:
|
||||
|
@ -414,8 +414,23 @@ class IOUDevice(object):
|
||||
|
||||
if not self.is_running():
|
||||
|
||||
if not os.path.isfile(self._path):
|
||||
raise IOUError("IOU '{}' is not accessible".format(self._path))
|
||||
if not os.path.isfile(iou_path):
|
||||
raise IOUError("IOU image '{}' is not accessible".format(iou_path))
|
||||
|
||||
try:
|
||||
with open(iou_path, "rb") as f:
|
||||
# read the first 7 bytes of the file.
|
||||
elf_header_start = f.read(7)
|
||||
except OSError as e:
|
||||
raise IOUError("Cannot read ELF header for IOU image '{}': {}".format(self._path, e))
|
||||
|
||||
# IOU images must start with the ELF magic number, be 32-bit, little endian
|
||||
# and have an ELF version of 1 normal IOS image are big endian!
|
||||
if elf_header_start != b'\x7fELF\x01\x01\x01':
|
||||
raise IOUError("'{}' is not a valid IOU image".format(self._path))
|
||||
|
||||
if not os.access(self._path, os.X_OK):
|
||||
raise IOUError("IOU image '{}' is not executable".format(self._path))
|
||||
|
||||
if not self._iourc or not os.path.isfile(self._iourc):
|
||||
raise IOUError("A iourc file is necessary to start IOU")
|
||||
|
Loading…
Reference in New Issue
Block a user