Skip to content

Commit

Permalink
Merge branch 'bugfix/vfs_uart_outof_bounds_read_v4.4' into 'release/v…
Browse files Browse the repository at this point in the history
…4.4'

vfs_uart: fix out-of-bounds read (v4.4)

See merge request espressif/esp-idf!24314
  • Loading branch information
suda-morris committed Jun 26, 2023
2 parents 76122fb + a6b8788 commit 4aee265
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion components/touch_element/touch_slider.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ static uint32_t slider_filter_average(te_slider_handle_t slider_handle, uint32_t
for (int win_idx = 0; win_idx < TE_SLD_DEFAULT_POS_FILTER_SIZE(s_te_sld_obj); win_idx++) { //Moving average filter
position_average += slider_handle->pos_filter_window[win_idx];
}
position_average = position_average / TE_SLD_DEFAULT_POS_FILTER_SIZE(s_te_sld_obj) + 0.5;
position_average = (uint32_t)((float)position_average / TE_SLD_DEFAULT_POS_FILTER_SIZE(s_te_sld_obj) + 0.5F);
return position_average;
}

Expand Down
2 changes: 1 addition & 1 deletion components/usb/hcd_dwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ static inline void _buffer_parse_isoc(dma_buffer_block_t *buffer, bool is_in)
usb_dwc_hal_xfer_desc_parse(buffer->xfer_desc_list, desc_idx, &rem_len, &desc_status);
usb_dwc_hal_xfer_desc_clear(buffer->xfer_desc_list, desc_idx);
assert(rem_len == 0 || is_in);
assert(desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS || USB_DWC_HAL_XFER_DESC_STS_NOT_EXECUTED);
assert(desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS || desc_status == USB_DWC_HAL_XFER_DESC_STS_NOT_EXECUTED);
assert(rem_len <= transfer->isoc_packet_desc[pkt_idx].num_bytes); //Check for DMA errata
//Update ISO packet actual length and status
transfer->isoc_packet_desc[pkt_idx].actual_num_bytes = transfer->isoc_packet_desc[pkt_idx].num_bytes - rem_len;
Expand Down
26 changes: 17 additions & 9 deletions components/vfs/vfs_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ static vfs_uart_context_t* s_ctx[UART_NUM] = {
#endif
};

static const char *s_uart_mount_points[UART_NUM] = {
"/0",
"/1",
#if UART_NUM > 2
"/2",
#endif
};

#ifdef CONFIG_VFS_SUPPORT_SELECT

typedef struct {
Expand All @@ -126,21 +134,21 @@ static esp_err_t uart_end_select(void *end_select_args);

#endif // CONFIG_VFS_SUPPORT_SELECT

static int uart_open(const char * path, int flags, int mode)
static int uart_open(const char *path, int flags, int mode)
{
// this is fairly primitive, we should check if file is opened read only,
// and error out if write is requested
int fd = -1;

if (strcmp(path, "/0") == 0) {
fd = 0;
} else if (strcmp(path, "/1") == 0) {
fd = 1;
} else if (strcmp(path, "/2") == 0) {
fd = 2;
} else {
for (int i = 0; i < UART_NUM; i++) {
if (strcmp(path, s_uart_mount_points[i]) == 0) {
fd = i;
break;
}
}
if (fd == -1) {
errno = ENOENT;
return fd;
return -1;
}

s_ctx[fd]->non_blocking = ((flags & O_NONBLOCK) == O_NONBLOCK);
Expand Down

0 comments on commit 4aee265

Please sign in to comment.