Skip to content

Commit

Permalink
stop testing symlinks/blockdevices against VALID_RAW_CONTENT
Browse files Browse the repository at this point in the history
as they are real devices on the system(usually disks!) let's
 not try and test them to see if they are a valid content
 just trust the kernel, it probably knows best.
  • Loading branch information
a-a authored and alinefm committed Apr 19, 2019
1 parent bc66961 commit c56b06d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions model/storagevolumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,23 @@ def lookup(self, pool, name):
# raw files), so it's necessary check the 'content' of them
isvalid = True
if fmt == 'raw':
try:
ms = magic.open(magic.NONE)
ms.load()
if ms.file(path).lower() not in VALID_RAW_CONTENT:
if not os.path.islink(path): # Check if file is a symlink to a real block device, if so, don't check it's contents for validity
try:
ms = magic.open(magic.NONE)
ms.load()
if ms.file(path).lower() not in VALID_RAW_CONTENT:
isvalid = False
ms.close()
except UnicodeDecodeError:
isvalid = False
ms.close()
except UnicodeDecodeError:
isvalid = False
else: # We are a symlink
if "/dev/dm-" in os.path.realpath(path):
# This is most likely a real blockdevice
isvalid = True
wok_log.error("symlink detected, validated the disk")
else:
# Doesn't point to a known blockdevice
isvalid = False

used_by = get_disk_used_by(self.conn, path)
if (self.libvirt_user is None):
Expand Down

0 comments on commit c56b06d

Please sign in to comment.