mirror of
https://github.com/esphome/esphome.git
synced 2026-09-15 17:18:40 +00:00
[api][at581x][vl53l0x] Fix bounds check issues in 3 components (#14660)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
a379e5a635
commit
75f55adbfa
@@ -375,6 +375,7 @@ void APINoiseFrameHelper::send_explicit_handshake_reject_(const LogString *reaso
|
||||
#ifdef USE_STORE_LOG_STR_IN_FLASH
|
||||
// On ESP8266 with flash strings, we need to use PROGMEM-aware functions
|
||||
size_t reason_len = strlen_P(reinterpret_cast<PGM_P>(reason));
|
||||
reason_len = std::min(reason_len, sizeof(data) - 1);
|
||||
if (reason_len > 0) {
|
||||
memcpy_P(data + 1, reinterpret_cast<PGM_P>(reason), reason_len);
|
||||
}
|
||||
@@ -382,6 +383,7 @@ void APINoiseFrameHelper::send_explicit_handshake_reject_(const LogString *reaso
|
||||
// Normal memory access
|
||||
const char *reason_str = LOG_STR_ARG(reason);
|
||||
size_t reason_len = strlen(reason_str);
|
||||
reason_len = std::min(reason_len, sizeof(data) - 1);
|
||||
if (reason_len > 0) {
|
||||
// NOLINTNEXTLINE(bugprone-not-null-terminated-result) - binary protocol, not a C string
|
||||
std::memcpy(data + 1, reason_str, reason_len);
|
||||
|
||||
@@ -135,6 +135,11 @@ bool AT581XComponent::i2c_write_config() {
|
||||
}
|
||||
|
||||
// Set gain
|
||||
if (this->gain_ < 0 || static_cast<size_t>(this->gain_) >= ARRAY_SIZE(GAIN5C_TABLE) ||
|
||||
static_cast<size_t>(this->gain_ >> 1) >= ARRAY_SIZE(GAIN63_TABLE)) {
|
||||
ESP_LOGE(TAG, "AT581X gain index out of range: %d", this->gain_);
|
||||
return false;
|
||||
}
|
||||
if (!this->i2c_write_reg(GAIN_ADDR_TABLE[0], GAIN5C_TABLE[this->gain_]) ||
|
||||
!this->i2c_write_reg(GAIN_ADDR_TABLE[1], GAIN63_TABLE[this->gain_ >> 1])) {
|
||||
ESP_LOGE(TAG, "Failed to write AT581X gain registers");
|
||||
|
||||
@@ -87,9 +87,9 @@ void VL53L0XSensor::setup() {
|
||||
reg(0x94) = 0x6B;
|
||||
reg(0x83) = 0x00;
|
||||
|
||||
this->timeout_start_us_ = micros();
|
||||
uint32_t timeout_start_us = micros();
|
||||
while (reg(0x83).get() == 0x00) {
|
||||
if (this->timeout_us_ > 0 && ((uint16_t) (micros() - this->timeout_start_us_) > this->timeout_us_)) {
|
||||
if (this->timeout_us_ > 0 && (micros() - timeout_start_us > this->timeout_us_)) {
|
||||
ESP_LOGE(TAG, "'%s' - setup timeout", this->name_.c_str());
|
||||
this->mark_failed();
|
||||
return;
|
||||
|
||||
@@ -64,8 +64,7 @@ class VL53L0XSensor : public sensor::Sensor, public PollingComponent, public i2c
|
||||
bool waiting_for_interrupt_{false};
|
||||
uint8_t stop_variable_;
|
||||
|
||||
uint16_t timeout_start_us_;
|
||||
uint16_t timeout_us_{};
|
||||
uint32_t timeout_us_{};
|
||||
|
||||
static std::list<VL53L0XSensor *> vl53_sensors; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
static bool enable_pin_setup_complete; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
Reference in New Issue
Block a user