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 <stijn@ignitron.net>
This commit is contained in:
stijn 2023-11-06 15:48:13 +01:00 committed by Damien George
parent 3b954698fa
commit 365913953a
1 changed files with 9 additions and 9 deletions

View File

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