From cffdc2f0cfbfb3fa12fd5a69a3fe1d9a3fe5093e Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sun, 3 May 2020 18:11:18 +0200 Subject: [PATCH] Add checks for get_part errors --- qloader2.bin | Bin 32768 -> 32768 bytes src/drivers/disk.c | 1 + src/fs/echfs.c | 8 ++++++-- src/fs/ext2fs.c | 8 ++++++-- src/fs/fat32.c | 4 +++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/qloader2.bin b/qloader2.bin index 873de69d7cc8a2a15e092c9f3a96a65fa2598f35..87e3c9172f71c5987c0e4a356fff8b9c43f74264 100644 GIT binary patch delta 5806 zcma)AdstIfwmC|4L&a^5TQDYiw zXHCCaJGLNg$J#pAN`3aLgVh@GRXSs*&givZ)j1eiv0Amh&Ry#Ssb2l#p6}axul-w( zz4qE`Ka%=-zP_H{?yU;uIyuhiyX7L*dZOdLzP4353z4evOn?eibj8^Yj6dYsv5igBx>0@bT!S#k+7e( z|D=2G3)O)RRdYM_^{3#R%203w>3pa8h#=GkN>h>)D>uwXSY48>TPvrYLbjYr3bIw> zFkjH^IwXkW4&$(Ej3gT*R#0bVG+I>Lw5Ohh8uf$-azt>LTfNL$L2@T@9J96tEIEWe zcD)0K)Hz{8?#pta{bG@&V0rf*FOG9q{l!YMwH*fc8@bGX1ew?Bb~SY0lVt(hAE*_r zBr?muab=ad-3>j6;f!><-}n(J)-H%^i9Zhc#ihvSa1amwelLFm@gtC5Qign0AD>5x z^mh>dZWIbs7NdZsPoQ6~KpP31g+K#e8T%*#}(k}w8(+!K7&$wu)Bw=AHW^vjB5mDYvt1$UmL(#dt7SLrLWDs z+odKoh8_1uNW(^-?17F1Wn{;ayKM(C{ABPapX4;sDlIGT3Pev3wiMV8*wTZ@lx`)5 ztK%HsKF()Rv_s#G7N6()>-M)fCu!R4d{YNh^dHXFfU|$ZGGb~`$))Z<>H?Oo$*62g zmyqP@`n%Nr$Yn@7d}+kb8j-XgN&frIYiSB=iMp923JMaGt~>kxqw3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B@by0(Z5MeF3&tSMfckWO+5!1|-i-mpbLZyr!T5_{26WFG1?_Xw zc-2{1{tM2+AZlJZH}2n1I&T%b5x$%E4xfartV3bFIX`(4C03^#K%#sXwnpXZ|C@z= X;LzVP{`e$1?|dt}Kn??g-^%|7CEJ4J diff --git a/src/drivers/disk.c b/src/drivers/disk.c index b04474cf..5621e50f 100644 --- a/src/drivers/disk.c +++ b/src/drivers/disk.c @@ -44,6 +44,7 @@ static int cache_block(int drive, uint64_t block) { if (r.eflags & EFLAGS_CF) { int ah = (r.eax >> 8) & 0xff; print("Disk error %x. Drive %x, LBA %x.\n", ah, drive, dap.lba); + panic(""); cached_block = CACHE_INVALID; return ah; } diff --git a/src/fs/echfs.c b/src/fs/echfs.c index ceddfe13..bc9c79ea 100644 --- a/src/fs/echfs.c +++ b/src/fs/echfs.c @@ -40,7 +40,9 @@ int echfs_read(struct echfs_file_handle *file, void *buf, uint64_t loc, uint64_t int echfs_check_signature(int disk, int partition) { struct part part; - get_part(&part, disk, partition); + if (get_part(&part, disk, partition)) { + panic("Invalid partition"); + } struct echfs_identity_table id_table; read_partition(disk, &part, &id_table, 0, sizeof(struct echfs_identity_table)); @@ -57,7 +59,9 @@ int echfs_open(struct echfs_file_handle *ret, int disk, int partition, const cha ret->disk = disk; - get_part(&ret->part, disk, partition); + if (get_part(&ret->part, disk, partition)) { + panic("Invalid partition"); + } struct echfs_identity_table id_table; read_partition(disk, &ret->part, &id_table, 0, sizeof(struct echfs_identity_table)); diff --git a/src/fs/ext2fs.c b/src/fs/ext2fs.c index 54fe75a7..093fa3a8 100644 --- a/src/fs/ext2fs.c +++ b/src/fs/ext2fs.c @@ -265,7 +265,9 @@ next: } int ext2fs_open(struct ext2fs_file_handle *ret, int drive, int partition, const char *path) { - get_part(&ret->part, drive, partition); + if (get_part(&ret->part, drive, partition)) { + panic("Invalid partition"); + } ret->drive = drive; @@ -353,7 +355,9 @@ static int inode_read(void *buf, uint64_t loc, uint64_t count, // attempts to initialize the ext2 filesystem int ext2fs_check_signature(int drive, int partition) { struct part part; - get_part(&part, drive, partition); + if (get_part(&part, drive, partition)) { + panic("Invalid partition"); + } uint16_t magic = 0; diff --git a/src/fs/fat32.c b/src/fs/fat32.c index ff6505f2..7a5f2c36 100644 --- a/src/fs/fat32.c +++ b/src/fs/fat32.c @@ -67,7 +67,9 @@ struct fat32_lfn_entry { static int fat32_init_context(struct fat32_context* context, int disk, int partition) { context->drive = disk; - get_part(&context->part, disk, partition); + if (get_part(&context->part, disk, partition)) { + panic("Invalid partition"); + } struct fat32_bpb bpb; read_partition(disk, &context->part, &bpb, 0, sizeof(struct fat32_bpb));