mirror of
https://github.com/esphome/esphome.git
synced 2026-09-23 21:14:03 +00:00
[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:
co-authored by
J. Nick Koston
parent
44d314d069
commit
6f0460b0ee
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user