mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
vfs_uart: fix out-of-bounds read
when open uart device "/2" on chips only have 2 UART peripherals
This commit is contained in:
parent
96119acc8b
commit
93ce0714fd
@ -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 {
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user