mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: DisconnectReason::decode should return error on zero length list (#7284)
This commit is contained in:
@ -129,9 +129,14 @@ impl Decodable for DisconnectReason {
|
|||||||
// this should be a list, so decode the list header. this should advance the buffer so
|
// this should be a list, so decode the list header. this should advance the buffer so
|
||||||
// buf[0] is the first (and only) element of the list.
|
// buf[0] is the first (and only) element of the list.
|
||||||
let header = Header::decode(buf)?;
|
let header = Header::decode(buf)?;
|
||||||
|
|
||||||
if !header.list {
|
if !header.list {
|
||||||
return Err(RlpError::UnexpectedString)
|
return Err(RlpError::UnexpectedString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if header.payload_length != 1 {
|
||||||
|
return Err(RlpError::ListLengthMismatch { expected: 1, got: header.payload_length })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// geth rlp encodes [`DisconnectReason::DisconnectRequested`] as 0x00 and not as empty
|
// geth rlp encodes [`DisconnectReason::DisconnectRequested`] as 0x00 and not as empty
|
||||||
@ -232,6 +237,14 @@ mod tests {
|
|||||||
assert!(DisconnectReason::decode(&mut &[0u8; 3][..]).is_err())
|
assert!(DisconnectReason::decode(&mut &[0u8; 3][..]).is_err())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_reason_zero_length_list() {
|
||||||
|
let list_with_zero_length = hex::decode("c000").unwrap();
|
||||||
|
let res = DisconnectReason::decode(&mut &list_with_zero_length[..]);
|
||||||
|
assert!(res.is_err());
|
||||||
|
assert_eq!(res.unwrap_err().to_string(), "unexpected list length (got 0, expected 1)")
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn disconnect_encoding_length() {
|
fn disconnect_encoding_length() {
|
||||||
let all_reasons = all_reasons();
|
let all_reasons = all_reasons();
|
||||||
|
|||||||
Reference in New Issue
Block a user