Skip to content

Commit cc98bb0

Browse files
move stdio fd handle checking in fd_determine_type_rights to ensure type is properly set before return
1 parent ea408ab commit cc98bb0

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

  • core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -461,24 +461,6 @@ fd_determine_type_rights(os_file_handle fd, __wasi_filetype_t *type,
461461
struct __wasi_filestat_t buf;
462462
__wasi_errno_t error;
463463

464-
if (os_is_stdin_handle(fd)) {
465-
*rights_base = RIGHTS_STDIN;
466-
*rights_inheriting = RIGHTS_STDIN;
467-
return __WASI_ESUCCESS;
468-
}
469-
470-
if (os_is_stdout_handle(fd)) {
471-
*rights_base = RIGHTS_STDOUT;
472-
*rights_inheriting = RIGHTS_STDOUT;
473-
return __WASI_ESUCCESS;
474-
}
475-
476-
if (os_is_stderr_handle(fd)) {
477-
*rights_base = RIGHTS_STDERR;
478-
*rights_inheriting = RIGHTS_STDERR;
479-
return __WASI_ESUCCESS;
480-
}
481-
482464
error = os_fstat(fd, &buf);
483465
if (error != __WASI_ESUCCESS)
484466
return error;
@@ -542,6 +524,21 @@ fd_determine_type_rights(os_file_handle fd, __wasi_filetype_t *type,
542524
break;
543525
}
544526

527+
if (os_is_stdin_handle(fd)) {
528+
*rights_base = RIGHTS_STDIN;
529+
*rights_inheriting = RIGHTS_STDIN;
530+
}
531+
532+
if (os_is_stdout_handle(fd)) {
533+
*rights_base = RIGHTS_STDOUT;
534+
*rights_inheriting = RIGHTS_STDOUT;
535+
}
536+
537+
if (os_is_stderr_handle(fd)) {
538+
*rights_base = RIGHTS_STDERR;
539+
*rights_inheriting = RIGHTS_STDERR;
540+
}
541+
545542
return error;
546543
}
547544

0 commit comments

Comments
 (0)