fix: #1 ; next_state could be 0, which is invalid

This commit is contained in:
Tamipes 2026-01-16 09:59:08 +01:00
parent a58024c192
commit 0d8c04aea3

View file

@ -33,7 +33,7 @@ impl Handshake {
let next_state = VarInt::parse(&mut reader).await?; let next_state = VarInt::parse(&mut reader).await?;
// If you remove this, also fix get_next_state() to return an Option<> // If you remove this, also fix get_next_state() to return an Option<>
if next_state.get_int() > 3 || next_state.get_int() < 0 { if next_state.get_int() > 3 || next_state.get_int() < 1 {
return None; return None;
} }
Some(Handshake { Some(Handshake {
@ -48,11 +48,18 @@ impl Handshake {
self.server_address.get_value() self.server_address.get_value()
} }
pub fn get_next_state(&self) -> ProtocolState { pub fn get_next_state(&self) -> ProtocolState {
match self.next_state.get_int() { let state = self.next_state.get_int();
match state {
1 => ProtocolState::Status, 1 => ProtocolState::Status,
2 => ProtocolState::Login, 2 => ProtocolState::Login,
3 => ProtocolState::Transfer, 3 => ProtocolState::Transfer,
_ => unreachable!(), _ => {
tracing::error!(
next_state = state,
"invalid next_state for handshake packet!"
);
unreachable!()
}
} }
} }