iso directory traversal
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
Julien CLEMENT 2022-12-24 22:22:54 +01:00
parent 91095b7d08
commit d4add50d82
4 changed files with 34 additions and 9 deletions

@ -170,7 +170,7 @@ p2_table:
resb 4096 resb 4096
stack_bottom: stack_bottom:
resb 4 * 4096 resb 100 * 4096
stack_top: stack_top:

@ -1,4 +1,4 @@
const ISO_BLOCK_SIZE: usize = 2048; pub const ISO_BLOCK_SIZE: usize = 2048;
// Twin values structs // Twin values structs
@ -37,6 +37,7 @@ impl IsoPathTable {
// Directory structure // Directory structure
const ISO_MAX_DIR_DEPTH: usize = 8;
const ISO_DATE_LEN: usize = 7; const ISO_DATE_LEN: usize = 7;
#[repr(u8)] #[repr(u8)]

@ -4,6 +4,7 @@ pub mod iso9660;
use crate::drivers::atapi::DRIVE; use crate::drivers::atapi::DRIVE;
use crate::fd::{FDt, FD_TABLE}; use crate::fd::{FDt, FD_TABLE};
use crate::println; use crate::println;
use crate::serial_println;
use crate::utils::unserialize; use crate::utils::unserialize;
use super::FileSystem; use super::FileSystem;
@ -31,7 +32,7 @@ impl FileSystem for IsoFS {
} }
let root: IsoDir = voldesc.root_dir; 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() .lock()
.await .await
.as_mut() .as_mut()
@ -39,15 +40,38 @@ impl FileSystem for IsoFS {
.read_block(root.data_blk.le) .read_block(root.data_blk.le)
.await; .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 path_s: String = String::from(path);
let split_path: Vec<&str> = path_s let path_it = path_s
.split("/") .split("/")
.filter(|p| p != &"") .filter(|p| p != &"");
.collect();
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::<u8>().offset(curr_entry.dir_size as isize).cast::<IsoDir>();
}
}
}
let fd = IsoFD::new(); let fd = IsoFD::new();
FD_TABLE.lock().await.register_fd(fd.clone()); FD_TABLE.lock().await.register_fd(fd.clone());

@ -68,7 +68,7 @@ async fn get_file() {
let fd = fs::VIRTUAL_FS let fd = fs::VIRTUAL_FS
.lock() .lock()
.await .await
.open("///boot///grub.cfg", syscalls::io::O_RDONLY) .open("///boot/grub//grub.cfg", syscalls::io::O_RDONLY)
.await .await
.unwrap(); .unwrap();
fd.borrow_mut().read(&[], 0).await; fd.borrow_mut().read(&[], 0).await;