Skip to content

Commit 3659139

Browse files
stinosdpgeorge
authored andcommitted
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 micropython#12670. Signed-off-by: stijn <stijn@ignitron.net>
1 parent 3b95469 commit 3659139

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

extmod/vfs_posix_file.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,14 @@ STATIC const mp_stream_p_t vfs_posix_textio_stream_p = {
279279

280280
#if MICROPY_PY_SYS_STDIO_BUFFER
281281

282-
const mp_obj_vfs_posix_file_t mp_sys_stdin_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDIN_FILENO};
283-
const mp_obj_vfs_posix_file_t mp_sys_stdout_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDOUT_FILENO};
284-
const mp_obj_vfs_posix_file_t mp_sys_stderr_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDERR_FILENO};
282+
mp_obj_vfs_posix_file_t mp_sys_stdin_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDIN_FILENO};
283+
mp_obj_vfs_posix_file_t mp_sys_stdout_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDOUT_FILENO};
284+
mp_obj_vfs_posix_file_t mp_sys_stderr_buffer_obj = {{&mp_type_vfs_posix_fileio}, STDERR_FILENO};
285285

286286
// Forward declarations.
287-
const mp_obj_vfs_posix_file_t mp_sys_stdin_obj;
288-
const mp_obj_vfs_posix_file_t mp_sys_stdout_obj;
289-
const mp_obj_vfs_posix_file_t mp_sys_stderr_obj;
287+
mp_obj_vfs_posix_file_t mp_sys_stdin_obj;
288+
mp_obj_vfs_posix_file_t mp_sys_stdout_obj;
289+
mp_obj_vfs_posix_file_t mp_sys_stderr_obj;
290290

291291
STATIC void vfs_posix_textio_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
292292
if (dest[0] != MP_OBJ_NULL) {
@@ -332,8 +332,8 @@ MP_DEFINE_CONST_OBJ_TYPE(
332332
locals_dict, &vfs_posix_rawfile_locals_dict
333333
);
334334

335-
const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_vfs_posix_textio}, STDIN_FILENO};
336-
const mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_vfs_posix_textio}, STDOUT_FILENO};
337-
const mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_vfs_posix_textio}, STDERR_FILENO};
335+
mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_vfs_posix_textio}, STDIN_FILENO};
336+
mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_vfs_posix_textio}, STDOUT_FILENO};
337+
mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_vfs_posix_textio}, STDERR_FILENO};
338338

339339
#endif // MICROPY_VFS_POSIX

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy