fix: #1 ; next_state could be 0, which is invalid
This commit is contained in:
parent
a58024c192
commit
0d8c04aea3
1 changed files with 10 additions and 3 deletions
|
|
@ -33,7 +33,7 @@ impl Handshake {
|
|||
let next_state = VarInt::parse(&mut reader).await?;
|
||||
|
||||
// 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;
|
||||
}
|
||||
Some(Handshake {
|
||||
|
|
@ -48,11 +48,18 @@ impl Handshake {
|
|||
self.server_address.get_value()
|
||||
}
|
||||
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,
|
||||
2 => ProtocolState::Login,
|
||||
3 => ProtocolState::Transfer,
|
||||
_ => unreachable!(),
|
||||
_ => {
|
||||
tracing::error!(
|
||||
next_state = state,
|
||||
"invalid next_state for handshake packet!"
|
||||
);
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue