summaryrefslogtreecommitdiffstats
path: root/src/live
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-02 13:44:09 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-02 14:25:54 +0200
commit6704abc620fe52f180e7b21c2d6d7dd61a2eb3c2 (patch)
tree7b76d45f65b39d7968e35068d10f5861631b0346 /src/live
parentf2a2f5307464448989ff4b276f8ce5cee5c66b03 (diff)
live: add disk index bounds checkv1.3.2-16
Add disk index bounds checks for setup() and image_create(). Prevent backtrace logging when an invalid disk index is used.
Diffstat (limited to 'src/live')
-rw-r--r--src/live/ogOperations.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 5b55422..b1571d1 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -413,7 +413,7 @@ class OgLiveOperations:
def setup(self, request, ogRest):
table_type = request.getType()
- disk = request.getDisk()
+ disk = int(request.getDisk())
cache = request.getCache()
cache_size = request.getCacheSize()
partlist = request.getPartitionSetup()
@@ -424,7 +424,10 @@ class OgLiveOperations:
umount_all()
umount_cache()
- diskname = get_disks()[int(disk)-1]
+ if disk < 0 or disk > len(get_disks()):
+ raise OgError(f'Invalid disk number {disk}, {len(get_disks())} disks available.')
+
+ diskname = get_disks()[disk-1]
cxt = fdisk.Context(f'/dev/{diskname}',
details=True)
@@ -469,9 +472,9 @@ class OgLiveOperations:
partition = int(part["partition"])
if fs == 'cache':
- err = mkfs('ext4', int(disk), partition, label='CACHE')
+ err = mkfs('ext4', disk, partition, label='CACHE')
else:
- err = mkfs(fs, int(disk), partition)
+ err = mkfs(fs, disk, partition)
if err == -1:
raise OgError(f'Failed to format {part["partition"]} with filesystem {part["filesystem"]}')
@@ -554,6 +557,9 @@ class OgLiveOperations:
if ogRest.terminated:
return
+ if disk < 0 or disk > len(get_disks()):
+ raise OgError(f'Invalid disk number {disk}, {len(get_disks())} disks available.')
+
diskname = get_disks()[disk-1]
cxt = fdisk.Context(f'/dev/{diskname}', details=True)
pa = None