Skip to content
Snippets Groups Projects
Commit 5ccf474d authored by Bastian Köcher's avatar Bastian Köcher Committed by Gavin Wood
Browse files

Check filename length is valid in keystore (#4255)

parent c7916153
Branches
No related merge requests found
......@@ -226,7 +226,7 @@ impl Store {
// skip directories and non-unicode file names (hex is unicode)
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
match hex::decode(name) {
Ok(ref hex) => {
Ok(ref hex) if hex.len() > 4 => {
if &hex[0..4] != &key_type.0 { continue }
let public = TPublic::from_slice(&hex[4..]);
public_keys.push(public);
......@@ -422,4 +422,17 @@ mod tests {
assert_eq!(key_pair.public(), store_key_pair.public());
}
#[test]
fn store_ignores_files_with_invalid_name() {
let temp_dir = TempDir::new().unwrap();
let store = Store::open(temp_dir.path(), None).unwrap();
let file_name = temp_dir.path().join(hex::encode(&SR25519.0[..2]));
fs::write(file_name, "test").expect("Invalid file is written");
assert!(
store.read().public_keys_by_type::<sr25519::AppPublic>(SR25519).unwrap().is_empty(),
);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment