From d4add50d826b7f6b2f6253eec1a7e4718dcf9cf9 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Sat, 24 Dec 2022 22:22:54 +0100 Subject: [PATCH] iso directory traversal Signed-off-by: Julien CLEMENT --- src/boot/boot.asm | 2 +- src/fs/iso/iso9660.rs | 3 ++- src/fs/iso/mod.rs | 36 ++++++++++++++++++++++++++++++------ src/lib.rs | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/boot/boot.asm b/src/boot/boot.asm index df7501e..385a067 100644 --- a/src/boot/boot.asm +++ b/src/boot/boot.asm @@ -170,7 +170,7 @@ p2_table: resb 4096 stack_bottom: - resb 4 * 4096 + resb 100 * 4096 stack_top: diff --git a/src/fs/iso/iso9660.rs b/src/fs/iso/iso9660.rs index 663c03a..82e7354 100644 --- a/src/fs/iso/iso9660.rs +++ b/src/fs/iso/iso9660.rs @@ -1,4 +1,4 @@ -const ISO_BLOCK_SIZE: usize = 2048; +pub const ISO_BLOCK_SIZE: usize = 2048; // Twin values structs @@ -37,6 +37,7 @@ impl IsoPathTable { // Directory structure +const ISO_MAX_DIR_DEPTH: usize = 8; const ISO_DATE_LEN: usize = 7; #[repr(u8)] diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index 6336383..dc4fcb8 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -4,6 +4,7 @@ pub mod iso9660; use crate::drivers::atapi::DRIVE; use crate::fd::{FDt, FD_TABLE}; use crate::println; +use crate::serial_println; use crate::utils::unserialize; use super::FileSystem; @@ -31,7 +32,7 @@ impl FileSystem for IsoFS { } let root: IsoDir = voldesc.root_dir; - let curr_entry_block: [u8; 2048] = DRIVE + let mut curr_entry_block: [u8; iso9660::ISO_BLOCK_SIZE] = DRIVE .lock() .await .as_mut() @@ -39,15 +40,38 @@ impl FileSystem for IsoFS { .read_block(root.data_blk.le) .await; - let curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr()); + let mut curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr()); let path_s: String = String::from(path); - let split_path: Vec<&str> = path_s + let path_it = path_s .split("/") - .filter(|p| p != &"") - .collect(); + .filter(|p| p != &""); - println!("{:?}", split_path); + for path_component in path_it { + while curr_entry.idf_len != 0 { + serial_println!("{:?}", curr_entry.idf_len); + serial_println!("{:?}", alloc::str::from_utf8(curr_entry.get_idf()).unwrap()); + + if curr_entry.get_idf() == path_component.as_bytes() { + serial_println!("Found {}", path_component); + curr_entry_block = DRIVE + .lock() + .await + .as_mut() + .unwrap() + .read_block(curr_entry.data_blk.le) + .await; + curr_entry = unserialize(curr_entry_block.as_ptr()); + break; + } + + // Next entry + unsafe { + let curr_ptr: *const IsoDir = curr_entry; + curr_entry = &*curr_ptr.cast::().offset(curr_entry.dir_size as isize).cast::(); + } + } + } let fd = IsoFD::new(); FD_TABLE.lock().await.register_fd(fd.clone()); diff --git a/src/lib.rs b/src/lib.rs index b050757..32c7641 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,7 +68,7 @@ async fn get_file() { let fd = fs::VIRTUAL_FS .lock() .await - .open("///boot///grub.cfg", syscalls::io::O_RDONLY) + .open("///boot/grub//grub.cfg", syscalls::io::O_RDONLY) .await .unwrap(); fd.borrow_mut().read(&[], 0).await;