Skip to content

Commit

Permalink
Avoid panic when streaming packets are empty (#1861)
Browse files Browse the repository at this point in the history
* changed [] access to .get() to return result instead of panic

* changed error type to protocol err

* fixed issue with comparing ref

* cargo fmt

Co-authored-by: Erik Rhodes <erik@space-nav.com>
  • Loading branch information
junbl and Erik Rhodes authored Jun 1, 2022
1 parent 63291d6 commit c744cb7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sqlx-core/src/mysql/connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ impl MySqlStream {
// TODO: packet compression
// TODO: packet joining

if payload[0] == 0xff {
if payload
.get(0)
.ok_or(err_protocol!("Packet empty"))?
.eq(&0xff)
{
self.waiting.pop_front();

// instead of letting this packet be looked at everywhere, we check here
Expand Down

0 comments on commit c744cb7

Please sign in to comment.