vfs: select sanity NULL check

https://github.com/espressif/esp-idf/issues/9964
This commit is contained in:
Adam Múdry 2023-05-22 16:23:35 +02:00
parent ea5e0ff298
commit 3da76d4bd7
2 changed files with 18 additions and 4 deletions

View File

@ -990,7 +990,9 @@ int esp_vfs_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds
const vfs_entry_t *vfs = get_vfs_for_index(i); const vfs_entry_t *vfs = get_vfs_for_index(i);
fds_triple_t *item = &vfs_fds_triple[i]; fds_triple_t *item = &vfs_fds_triple[i];
if (vfs && vfs->vfs.start_select && item->isset) { if (vfs && !vfs->vfs.start_select) {
ESP_LOGD(TAG, "start_select function callback for this vfs (s_vfs[%d]) is not defined", vfs->offset);
} else if (vfs && vfs->vfs.start_select && item->isset) {
// call start_select for all non-socket VFSs with has at least one FD set in readfds, writefds, or errorfds // call start_select for all non-socket VFSs with has at least one FD set in readfds, writefds, or errorfds
// note: it can point to socket VFS but item->isset will be false for that // note: it can point to socket VFS but item->isset will be false for that
ESP_LOGD(TAG, "calling start_select for VFS ID %d with the following local FDs", i); ESP_LOGD(TAG, "calling start_select for VFS ID %d with the following local FDs", i);
@ -1001,7 +1003,9 @@ int esp_vfs_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds
driver_args + i); driver_args + i);
if (err != ESP_OK) { if (err != ESP_OK) {
call_end_selects(i, vfs_fds_triple, driver_args); if (err != ESP_ERR_NOT_SUPPORTED) {
call_end_selects(i, vfs_fds_triple, driver_args);
}
(void) set_global_fd_sets(vfs_fds_triple, vfs_count, readfds, writefds, errorfds); (void) set_global_fd_sets(vfs_fds_triple, vfs_count, readfds, writefds, errorfds);
if (sel_sem.is_sem_local && sel_sem.sem) { if (sel_sem.is_sem_local && sel_sem.sem) {
vSemaphoreDelete(sel_sem.sem); vSemaphoreDelete(sel_sem.sem);

View File

@ -119,12 +119,22 @@ int console_access(const char *path, int amode)
static esp_err_t console_start_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, static esp_err_t console_start_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
esp_vfs_select_sem_t select_sem, void **end_select_args) esp_vfs_select_sem_t select_sem, void **end_select_args)
{ {
return get_vfs_for_index(primary_vfs_index)->vfs.start_select(nfds, readfds, writefds, exceptfds, select_sem, end_select_args); const vfs_entry_t* vfs_entry = get_vfs_for_index(primary_vfs_index);
// start_select is not guaranteed be implemented even though CONFIG_VFS_SUPPORT_SELECT is enabled in sdkconfig
if (vfs_entry && vfs_entry->vfs.start_select) {
return vfs_entry->vfs.start_select(nfds, readfds, writefds, exceptfds, select_sem, end_select_args);
}
return ESP_ERR_NOT_SUPPORTED;
} }
esp_err_t console_end_select(void *end_select_args) esp_err_t console_end_select(void *end_select_args)
{ {
return get_vfs_for_index(primary_vfs_index)->vfs.end_select(end_select_args); const vfs_entry_t* vfs_entry = get_vfs_for_index(primary_vfs_index);
// end_select is not guaranteed be implemented even though CONFIG_VFS_SUPPORT_SELECT is enabled in sdkconfig
if (vfs_entry && vfs_entry->vfs.end_select) {
return vfs_entry->vfs.end_select(end_select_args);
}
return ESP_ERR_NOT_SUPPORTED;
} }
#endif // CONFIG_VFS_SUPPORT_SELECT #endif // CONFIG_VFS_SUPPORT_SELECT