From 02e7b7ea77a3bbc691a4d5082b18ea52a9d145a6 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sun, 2 Feb 2020 17:30:06 +0100 Subject: [PATCH] Potential bug that can overwrite the MBR of the host machine if no loop devices are available --- ProjectTree | 4 +++- build/create_disk.sh | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ProjectTree b/ProjectTree index eb17c00..d352829 100644 --- a/ProjectTree +++ b/ProjectTree @@ -54,6 +54,7 @@ │   │   ├── boot.h │   │   └── mboot.h │   ├── io +│   │   ├── acpi.h │   │   ├── ata.h │   │   ├── cursor.h │   │   ├── keyb.h @@ -94,6 +95,7 @@ │   │   │   ├── ssp.c │   │   │   └── table.c │   │   ├── io +│   │   │   ├── acpi.c │   │   │   ├── ata.asm │   │   │   ├── ata.c │   │   │   ├── cursor.c @@ -160,4 +162,4 @@ ├── ProjectTree └── README.md -28 directories, 107 files +28 directories, 109 files diff --git a/build/create_disk.sh b/build/create_disk.sh index 89f9b53..018b406 100755 --- a/build/create_disk.sh +++ b/build/create_disk.sh @@ -45,6 +45,12 @@ sudo losetup $lpblock $1 -o 1048576 echo ${CL2}[create_disk.sh]${NC} Sync image... \(sync\)${CL3} sync +if [ -z $lpblock ]; +then + echo No loop device partition to target. Fatal error ! + return 13 +fi + ## Format echo ${CL2}[create_disk.sh]${NC} Formatting image... \(mkdosfs\)${CL3} sudo mkdosfs -F32 -f 2 $lpblock @@ -61,6 +67,19 @@ lpblock=$(sudo losetup -f) sudo losetup $lpblock $1 -o 1048576 lpblockbase=$(sudo losetup -f) sudo losetup $lpblockbase $1 + +if [ -z $lpblockbase ]; +then + echo No loop device to target. Fatal error ! + return 13 +fi + +if [ -z $lpblock ]; +then + echo No loop device partition to target. Fatal error ! + return 13 +fi + sudo udisksctl mount -b $lpblock --no-user-interaction ## Sync