Skip to content

Commit

Permalink
Fixed buffer access bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fredilarsen committed Jan 1, 2020
1 parent b1ac824 commit d97619b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ReconnectingMqttClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,16 @@ class ReconnectingMqttClient {
}

void handle_suback(const uint8_t *buf, const uint16_t packet_len, const uint16_t payload_len, bool unsubscribe) {
if (packet_len == (unsubscribe ? 4 : 5) && buffer[0] == (unsubscribe ? UNSUBACK : SUBACK)) {
uint16_t mess_id = (buffer[2] << 8) | buffer[3];
if (!unsubscribe && buffer[4] > 2) return; // Return code indicates failure
if (packet_len == (unsubscribe ? 4 : 5) && buf[0] == (unsubscribe ? UNSUBACK : SUBACK)) {
uint16_t mess_id = (buf[2] << 8) | buf[3];
if (!unsubscribe && buf[4] > 2) return; // Return code indicates failure
if (mess_id == msg_id) last_sub_acked = true;
}
}

void handle_puback(const uint8_t *buf, const uint16_t packet_len, const uint16_t payload_len) {
if (packet_len == 4 && buffer[0] == PUBACK) {
pubacked_msg_id = (buffer[2] << 8) | buffer[3];
if (packet_len == 4 && buf[0] == PUBACK) {
pubacked_msg_id = (buf[2] << 8) | buf[3];
if (pubacked_msg_id == msg_id) last_pub_acked = true;
}
}
Expand Down

0 comments on commit d97619b

Please sign in to comment.