From 365913953a4e050eab45c00e637e92f612400b11 Mon Sep 17 00:00:00 2001 From: stijn Date: Mon, 6 Nov 2023 15:48:13 +0100 Subject: [PATCH] extmod/vfs_posix_file: Make standard file objects non-const. Fixes undefined behavior when calling vfs_posix_file_ioctl with MP_STREAM_CLOSE as request because that casts away the constness and assigns -1 to the object's fd member. Fixes issue #12670. Signed-off-by: stijn --- extmod/vfs_posix_file.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index 81a608d2b6..2f70789543 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -279,14 +279,14 @@ STATIC const mp_stream_p_t vfs_posix_textio_stream_p = { #if MICROPY_PY_SYS_STDIO_BUFFER -const mp_obj_vfs_posix_file_t mp_sys_stdin_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDIN_FILENO}; -const mp_obj_vfs_posix_file_t mp_sys_stdout_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDOUT_FILENO}; -const mp_obj_vfs_posix_file_t mp_sys_stderr_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDERR_FILENO}; +mp_obj_vfs_posix_file_t mp_sys_stdin_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDIN_FILENO}; +mp_obj_vfs_posix_file_t mp_sys_stdout_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDOUT_FILENO}; +mp_obj_vfs_posix_file_t mp_sys_stderr_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDERR_FILENO}; // Forward declarations. -const mp_obj_vfs_posix_file_t mp_sys_stdin_obj; -const mp_obj_vfs_posix_file_t mp_sys_stdout_obj; -const mp_obj_vfs_posix_file_t mp_sys_stderr_obj; +mp_obj_vfs_posix_file_t mp_sys_stdin_obj; +mp_obj_vfs_posix_file_t mp_sys_stdout_obj; +mp_obj_vfs_posix_file_t mp_sys_stderr_obj; STATIC void vfs_posix_textio_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { @@ -332,8 +332,8 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &vfs_posix_rawfile_locals_dict ); -const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_vfs_posix_textio}, STDIN_FILENO}; -const mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_vfs_posix_textio}, STDOUT_FILENO}; -const mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_vfs_posix_textio}, STDERR_FILENO}; +mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_vfs_posix_textio}, STDIN_FILENO}; +mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_vfs_posix_textio}, STDOUT_FILENO}; +mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_vfs_posix_textio}, STDERR_FILENO}; #endif // MICROPY_VFS_POSIX