Fix core dump bug in tree path search

This commit is contained in:
Michael Mikovsky
2026-03-18 12:01:21 -06:00
parent 95d335a271
commit 512823585f
4 changed files with 49 additions and 114 deletions
+4 -3
View File
@@ -1,11 +1,12 @@
use alloc::{boxed::Box, string::String, vec::Vec};
use crate::tree::request::{TreeRequest, TreeRequestType};
mod request;
pub use request::{TreeRequest, TreeRequestType};
pub mod types;
#[derive(Default)]
pub struct Tree {
endpoints: Vec<(Box<dyn Endpoint>, Vec<String>)>,
}
@@ -24,7 +25,7 @@ impl Tree {
return None;
}
for i in 0..search_path.len() {
for i in 0..endpoint_path.len() {
if search_path[i] != endpoint_path[i] {
return None;
}
+4 -5
View File
@@ -25,14 +25,13 @@ pub struct TreeRequest {
#[rkyv(compare(PartialEq), derive(Debug))]
pub enum TreeRequestType {
Return = 0,
Read = 1,
Write = 2,
Submit = 3,
GetProcedures = 2,
ListBranches = 10,
Write = 11,
CallProcedure = 12,
// CreateField = 3,
// DeleteField = 4,
UnnamedError = 100,
NoBranchError = 101,
ProtocolError = 102,
+13
View File
@@ -1,3 +1,16 @@
use alloc::{string::String, vec::Vec};
use crate::obfuscate::sym;
pub const TYPE_NONE: &'static str = sym!("core/None");
pub const TYPE_PROCEDURE_CALL_DESCRIPTOR: &'static str = sym!("core/Procedure_call_descriptor");
pub struct ProcedureCallDescriptor {
name: String,
}
pub const TYPE_PROCEDURE_CALL_DESCRIPTOR_LIST: &'static str =
sym!("core/Procedure_call_descriptor_list");
pub type ProcedureCallDescriptorList = Vec<ProcedureCallDescriptor>;
pub const TYPE_PROCEDURE_CALL_ARGUMENTS: &'static str = sym!("core/Procedure_call_arguments");
+28 -106
View File
@@ -1,117 +1,39 @@
#![macro_use]
extern crate unshell;
use unshell::{info, logger::PrettyLogger};
use unshell::{
info,
logger::PrettyLogger,
tree::{Endpoint, Tree, TreeRequest},
};
struct EndpointTest;
impl Endpoint for EndpointTest {
fn request(&mut self, request: TreeRequest) -> TreeRequest {
info!("Got request");
TreeRequest {
request_type: request.request_type,
path: request.path,
content_type: request.content_type,
data: request.data,
}
}
}
fn main() {
PrettyLogger::init();
// let mut manager = Tree::new();
// manager.init_logger();
info!("Initiated");
// println!("{}", sym!("TEST"));
let mut tree = Tree::default();
info!("Test thing!");
// info!("Test thing!");
tree.add_endpoint(EndpointTest, vec!["path1".to_string()]);
// loop {
// if test123(&mut manager) {
// break;
// }
// }
// println!("Test");
tree.request(TreeRequest {
path: vec!["path1".to_string(), "path2".to_string()],
request_type: unshell::tree::TreeRequestType::Read,
content_type: "TEST".to_string(),
data: Vec::new(),
});
}
// fn test123(manager: &mut Tree) -> bool {
// let result = manager.send_message(
// Value::String(sym!("Logger").to_string()),
// Value::String(symbols::CMD_GET.to_string()),
// );
// junk_asm!(20.);
// let is_null = result.is_null();
// // if let Ok(result) = serde_json::from_value::<Record>(result) {
// // log(&result);
// // }
// is_null
// // println!("Logger: {}", result);
// }
// use std::{any::Any, collections::HashMap, fs::File, io::Read};
// use static_init::dynamic;
// use unshell_lib::{
// ModuleError,
// config::{PayloadConfig, RuntimeConfig},
// module::{Manager, Module},
// };
// use unshell_obfuscate::{obs, symbol};
// #[macro_use]
// extern crate unshell_lib;
// // The main and initial 'configuration' for a payload
// #[dynamic]
// static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
// id: symbol!("Test ID"),
// components: Vec::new(),
// runtime_config: vec![RuntimeConfig {
// parent_component: symbol!("client").to_string(),
// name: symbol!("client runtime").to_string(),
// config: HashMap::from([
// (symbol!("host").to_string(), obs!("localhost:1234")),
// (symbol!("retry").to_string(), obs!("1000")),
// ]),
// }],
// };
// fn main() {
// debug!("Initialized");
// match run() {
// Ok(_) => {}
// Err(e) => {
// error!("ERROR! '{:?}'", e);
// }
// }
// }
// fn run() -> Result<(), Box<dyn std::error::Error>> {
// let args = std::env::args();
// // TEMPORARY, load the module paths from command line args.
// let mut modules = Vec::new();
// for arg in args.skip(1) {
// // debug!("Loading module: {}", arg);
// // let mut file = File::open(arg).map_err(|e| ModuleError::Error(e.to_string().into()))?;
// // let mut buffer = Vec::new();
// // file.read_to_end(&mut buffer)
// // .map_err(|e| ModuleError::Error(e.to_string().into()))?;
// debug!("Initializing module: {}", arg);
// let module = Module::new(&arg)?;
// modules.push(module);
// // modules.push(Module::new(&arg)?)
// }
// // let modules = vec
// debug!("Starting manager...");
// // Run the manager, this is blocking.
// let manager = Manager::start(&PAYLOAD_CONFIG, modules);
// Manager::join(manager);
// Ok(())
// }