From 337afbbe47663ca240e4892d6f161a52ff03670a Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 2 Nov 2021 03:26:16 +0800 Subject: [PATCH] bump loader version number --- loader/src/secboot.rs | 3 ++- services/pddb/src/lib.rs | 43 +++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/loader/src/secboot.rs b/loader/src/secboot.rs index 89ed8ef2d..f8a206023 100644 --- a/loader/src/secboot.rs +++ b/loader/src/secboot.rs @@ -2,9 +2,10 @@ use crate::println; pub const SIGBLOCK_SIZE: usize = 0x1000; -const VERSION_STR: &'static str = "Xous OS Loader v0.9.1\n\r"; +const VERSION_STR: &'static str = "Xous OS Loader v0.9.2\n\r"; // v0.9.0 -- initial version // v0.9.1 -- booting with hw acceleration, and "simplest signature" check on the entire xous.img blob +// v0.9.2 -- add version and length check between header and signed area pub const STACK_LEN: u32 = 8192 - (7 * 4); // 7 words for backup kernel args pub const STACK_TOP: u32 = 0x4100_0000 - STACK_LEN; diff --git a/services/pddb/src/lib.rs b/services/pddb/src/lib.rs index 627e32478..f8c676c99 100644 --- a/services/pddb/src/lib.rs +++ b/services/pddb/src/lib.rs @@ -10,7 +10,7 @@ use xous_ipc::Buffer; use num_traits::*; use std::io::{Result, Error, ErrorKind}; -use std::path::Path; +use std::path::{Path, Component}; use std::format; pub const PDDB_MAX_DICT_NAME_LEN: usize = 64; @@ -28,32 +28,39 @@ impl PddbKey { REFCOUNT.store(REFCOUNT.load(Ordering::Relaxed) + 1, Ordering::Relaxed); let conn = xns.request_connection_blocking(api::SERVER_NAME_PDDB).expect("Can't connect to Pddb server"); - if !path.is_absolute() { - return Err(Error::new(ErrorKind::InvalidInput, "All Xous keys must be fully specified relative to a dictionary")); + if !path.as_ref().is_absolute() { + return Err(Error::new(ErrorKind::InvalidInput, "All PDDB keys must be fully specified relative to a dictionary")); } let mut dict = String::new(); let mut key = String::new(); - if let Some(pathstr) = path.to_str() { - if let Some(path_lstrip) = path.strip_prefix("/") { - if let Some((dictstr, keystr)) = path_lstrip.split_once("/") { - if dictstr.len() < PDDB_MAX_DICT_NAME_LEN { + let mut components = path.as_ref().components(); + match components.next().unwrap() { + Component::Prefix(prefix_component) => { + if let Some(dictstr) = prefix_component.as_os_str().to_str() { + if dictstr.len() <= PDDB_MAX_DICT_NAME_LEN { dict.push_str(dictstr); } else { - return Err(Error::new(ErrorKind::InvalidInput, format!("Xous dictionary names must be shorter than {} bytes", PDDB_MAX_DICT_NAME_LEN))); - } - if keystr.len() < PDDB_MAX_KEY_NAME_LEN { - key.push_str(keystr); - } else { - return Err(Error::new(ErrorKind::InvalidInput, format!("Xous key names must be shorter than {} bytes", PDDB_MAX_DICT_NAME_LEN))); + return Err(Error::new(ErrorKind::InvalidInput, format!("PDDB dictionary names must be shorter than {} bytes", PDDB_MAX_DICT_NAME_LEN))); } } else { - return Err(Error::new(ErrorKind::InvalidInput, "All Xous keys must be of the format /dict/key; the key may contain more /'s")); + return Err(Error::new(ErrorKind::InvalidInput, "PDDB dictionary names must valid UTF-8")); } - } else { - return Err(Error::new(ErrorKind::InvalidInput, "All Xous keys must be absolute and start with a /")); } - } else { - return Err(Error::new(ErrorKind::InvalidInput, "All Xous keys must be valid UTF-8")); + _ => { + return Err(Error::new(ErrorKind::InvalidInput, "All PDDB entries must be of the format `dict:key`, where `dict` is treated as a Prefix")); + } + } + // collect the remaining components into the key + for comps in components { + if let Some(keystr) = comps.as_os_str().to_str() { + key.push_str(keystr); + } else { + return Err(Error::new(ErrorKind::InvalidInput, "PDDB dictionary names must valid UTF-8")); + } + } + + if key.len() > PDDB_MAX_KEY_NAME_LEN { + return Err(Error::new(ErrorKind::InvalidInput, format!("PDDB key names must be shorter than {} bytes", PDDB_MAX_DICT_NAME_LEN))); } let request = PddbKeyRequest {