Skip to content

Commit

Permalink
Avoid panicking if packet empty (#1667)
Browse files Browse the repository at this point in the history
I'm having panics on those index accesses, an empty packet is probably a symptom of other problems, but it would be cool if the application doesn't panics like it does.
  • Loading branch information
nappa85 authored Feb 16, 2022
1 parent 7fb54d3 commit 2849468
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sqlx-core/src/mysql/connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl MySqlStream {
while self.waiting.front() == Some(&Waiting::Row) {
let packet = self.recv_packet().await?;

if packet[0] == 0xfe && packet.len() < 9 {
if !packet.is_empty() && packet[0] == 0xfe && packet.len() < 9 {
let eof = packet.eof(self.capabilities)?;

if eof.status.contains(Status::SERVER_MORE_RESULTS_EXISTS) {
Expand All @@ -97,7 +97,7 @@ impl MySqlStream {
while self.waiting.front() == Some(&Waiting::Result) {
let packet = self.recv_packet().await?;

if packet[0] == 0x00 || packet[0] == 0xff {
if !packet.is_empty() && (packet[0] == 0x00 || packet[0] == 0xff) {
let ok = packet.ok()?;

if !ok.status.contains(Status::SERVER_MORE_RESULTS_EXISTS) {
Expand Down

0 comments on commit 2849468

Please sign in to comment.