Merge pull request #6320 from mwisslead/pulseio_pulsin_buffer_overread
Fix PulseIn buffer overread in popleft #6318
This commit is contained in:
commit
02280b81ef
|
@ -132,7 +132,7 @@ void pulsein_interrupt_handler(uint8_t channel) {
|
|||
if (self->len < self->maxlen) {
|
||||
self->len++;
|
||||
} else {
|
||||
self->start++;
|
||||
self->start = (self->start + 1) % self->maxlen;
|
||||
}
|
||||
}
|
||||
self->last_overflow = current_overflow;
|
||||
|
|
|
@ -75,7 +75,7 @@ static int pulsein_interrupt_handler(int irq, FAR void *context, FAR void *arg)
|
|||
if (self->len < self->maxlen) {
|
||||
self->len++;
|
||||
} else {
|
||||
self->start++;
|
||||
self->start = (self->start + 1) % self->maxlen;
|
||||
}
|
||||
}
|
||||
self->last_us = current_us;
|
||||
|
|
|
@ -42,19 +42,19 @@ STATIC void update_internal_buffer(pulseio_pulsein_obj_t *self) {
|
|||
for (size_t i = 0; i < length; i++) {
|
||||
uint16_t pos = (self->start + self->len) % self->maxlen;
|
||||
self->buffer[pos] = items[i].duration0 * 3;
|
||||
// Check if second item exists before incrementing
|
||||
if (items[i].duration1) {
|
||||
self->buffer[pos + 1] = items[i].duration1 * 3;
|
||||
if (self->len < (self->maxlen - 1)) {
|
||||
self->len += 2;
|
||||
} else {
|
||||
self->start += 2;
|
||||
}
|
||||
if (self->len < self->maxlen) {
|
||||
self->len++;
|
||||
} else {
|
||||
self->start = (self->start + 1) % self->maxlen;
|
||||
}
|
||||
// Check if second item exists
|
||||
if (items[i].duration1) {
|
||||
pos = (self->start + self->len) % self->maxlen;
|
||||
self->buffer[pos] = items[i].duration1 * 3;
|
||||
if (self->len < self->maxlen) {
|
||||
self->len++;
|
||||
} else {
|
||||
self->start++;
|
||||
self->start = (self->start + 1) % self->maxlen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ static void _pulsein_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action
|
|||
if (self->len < self->maxlen) {
|
||||
self->len++;
|
||||
} else {
|
||||
self->start++;
|
||||
self->start = (self->start + 1) % self->maxlen;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ STATIC void pulsein_exti_event_handler(uint8_t num) {
|
|||
if (self->len < self->maxlen) {
|
||||
self->len++;
|
||||
} else {
|
||||
self->start++;
|
||||
self->start = (self->start + 1) % self->maxlen;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue