mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 04:51:01 +00:00
Check filename length is valid in keystore (#4255)
This commit is contained in:
committed by
Gavin Wood
parent
c791615387
commit
5ccf474d8d
@@ -226,7 +226,7 @@ impl Store {
|
|||||||
// skip directories and non-unicode file names (hex is unicode)
|
// skip directories and non-unicode file names (hex is unicode)
|
||||||
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
|
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
|
||||||
match hex::decode(name) {
|
match hex::decode(name) {
|
||||||
Ok(ref hex) => {
|
Ok(ref hex) if hex.len() > 4 => {
|
||||||
if &hex[0..4] != &key_type.0 { continue }
|
if &hex[0..4] != &key_type.0 { continue }
|
||||||
let public = TPublic::from_slice(&hex[4..]);
|
let public = TPublic::from_slice(&hex[4..]);
|
||||||
public_keys.push(public);
|
public_keys.push(public);
|
||||||
@@ -422,4 +422,17 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(key_pair.public(), store_key_pair.public());
|
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(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user