Avoid panic when streaming packets are empty (#1861)

* 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>
This commit is contained in:
Erik Rhodes 2022-05-31 18:58:49 -06:00 committed by GitHub
parent 63291d677f
commit c744cb7f60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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