Merge pull request #6320 from mwisslead/pulseio_pulsin_buffer_overread

Fix PulseIn buffer overread in popleft #6318
This commit is contained in:
Mark 2022-04-28 07:42:44 -05:00 committed by GitHub
commit 02280b81ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 13 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}