Skip to content

Commit f17fd71

Browse files
committed
smart_battery: Reject non-hex characters in the auth key
The length check counts bytes, so a 32 byte key containing a multi-byte UTF-8 character could make the two character slices split a character and panic. u8::from_str_radix also accepts a leading '+', so "+a" was silently taken as 0x0A. Check that every character is a hex digit before parsing.
1 parent d984fd7 commit f17fd71

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎framework_lib/src/smart_battery.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,11 @@ impl SmartBattery {
974974
input_text.len()
975975
)));
976976
}
977+
if !input_text.bytes().all(|byte| byte.is_ascii_hexdigit()) {
978+
return Err(EcError::DeviceError(
979+
"Authentication key contains a non-hex character".to_string(),
980+
));
981+
}
977982

978983
let mut auth_key = [0u8; 16];
979984
for i in 0..16 {

0 commit comments

Comments
 (0)