You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, congratulations on the project — it's really fascinating and well-designed!
While experimenting with the system, I encountered some emulator crashes when using the diskrm command in the shell provided with fox32os 0.3.0. Specifically:
Attempting to remove a disk that was never mounted results in a segmentation fault.
Attempting to remove an already removed disk causes a double free error, leading to an emulator abort.
I believe the issue originates from the following function:
voidremove_disk(size_tid) {
if (id>3) { puts("attempting to access disk with ID > 3"); return; }
printf("unmounting disk ID %d\n", (int) id);
/* >>> Abort! <<< */fclose(disk_controller.disks[id].file);
disk_controller.disks[id].size=0;
}
The problem seems to stem from the lack of validation on disk_controller.disks[id].file. If the pointer is NULL, calling fclose results in undefined behavior. Additionally, once the file is closed, the pointer is not set to NULL, making a second call to remove_disk(id) cause a double free.
A potential fix could be:
voidremove_disk(size_tid) {
if (id>3) { puts("attempting to access disk with ID > 3"); return; }
printf("unmounting disk ID %d\n", (int) id);
/* Prevent segmentation fault by ensuring the file pointer is valid */if (disk_controller.disks[id].file) {
fclose(disk_controller.disks[id].file);
disk_controller.disks[id].size=0;
/* Prevent double free by setting the pointer to NULL */disk_controller.disks[id].file=NULL;
}
}
Additionally, if I understand correctly, disk 0 is the one from which the operating system boots. It might be a good idea to prevent its removal entirely, possibly by adding a check inside the OS shell command (diskrm.asm). A warning message could notify users that disk 0 cannot be removed.
Let me know what you think! Thanks for your hard work on this project.
The text was updated successfully, but these errors were encountered:
Hello,
First of all, congratulations on the project — it's really fascinating and well-designed!
While experimenting with the system, I encountered some emulator crashes when using the diskrm command in the shell provided with fox32os 0.3.0. Specifically:
I believe the issue originates from the following function:
The problem seems to stem from the lack of validation on
disk_controller.disks[id].file
. If the pointer isNULL
, callingfclose
results in undefined behavior. Additionally, once the file is closed, the pointer is not set toNULL
, making a second call toremove_disk(id)
cause a double free.A potential fix could be:
Additionally, if I understand correctly,
disk 0
is the one from which the operating system boots. It might be a good idea to prevent its removal entirely, possibly by adding a check inside the OS shell command (diskrm.asm
). A warning message could notify users that disk 0 cannot be removed.Let me know what you think! Thanks for your hard work on this project.
The text was updated successfully, but these errors were encountered: