check UDP packet's data length before decrypt_packet

fixes shadowsocks/crypto2#8
This commit is contained in:
zonyitoo
2020-12-31 19:58:22 +08:00
parent 474e57a331
commit 9abf3847c1

View File

@@ -219,6 +219,10 @@ async fn decrypt_payload_aead(
let mut cipher = Cipher::new(method, &key, &salt);
let tag_len = cipher.tag_len();
if data.len() < tag_len {
return Err(io::Error::new(io::ErrorKind::Other, "udp packet too short for tag"));
}
if !cipher.decrypt_packet(data) {
return Err(io::Error::new(io::ErrorKind::Other, "invalid tag-in"));
}