[sim800l][tormatic][tx20] Fix OOB access, div-by-zero, and off-by-one (#14512)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Jonathan Swoboda
2026-03-05 09:46:47 -10:00
committed by GitHub
co-authored by J. Nick Koston
parent 44d314d069
commit 6f0460b0ee
3 changed files with 7 additions and 3 deletions
+3 -2
View File
@@ -196,7 +196,8 @@ void Sim800LComponent::parse_cmd_(std::string message) {
case STATE_CREG_WAIT: {
// Response: "+CREG: 0,1" -- the one there means registered ok
// "+CREG: -,-" means not registered ok
bool registered = message.compare(0, 6, "+CREG:") == 0 && (message[9] == '1' || message[9] == '5');
bool registered =
message.size() > 9 && message.compare(0, 6, "+CREG:") == 0 && (message[9] == '1' || message[9] == '5');
if (registered) {
if (!this->registered_) {
ESP_LOGD(TAG, "Registered OK");
@@ -205,7 +206,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
this->expect_ack_ = true;
} else {
ESP_LOGW(TAG, "Registration Fail");
if (message[7] == '0') { // Network registration is disable, enable it
if (message.size() > 7 && message[7] == '0') { // Network registration is disabled, enable it
send_cmd_("AT+CREG=1");
this->expect_ack_ = true;
this->state_ = STATE_SETUP_CMGF;
@@ -183,6 +183,9 @@ void Tormatic::recompute_position_() {
duration = this->close_duration_;
}
if (duration == 0)
return;
auto delta = direction * diff / duration;
this->position = clamp(this->position + delta, COVER_CLOSED, COVER_OPEN);
+1 -1
View File
@@ -191,7 +191,7 @@ void IRAM_ATTR Tx20ComponentStore::gpio_intr(Tx20ComponentStore *arg) {
arg->tx20_available = true;
return;
}
if (index <= MAX_BUFFER_SIZE) {
if (index < MAX_BUFFER_SIZE) {
arg->buffer[index] = delay;
}
arg->spent_time += delay;