Skip to content

move stdio fd handle checking in fd_determine_type_rights to ensure type is properly set before return #4395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -461,24 +461,6 @@ fd_determine_type_rights(os_file_handle fd, __wasi_filetype_t *type,
struct __wasi_filestat_t buf;
__wasi_errno_t error;

if (os_is_stdin_handle(fd)) {
*rights_base = RIGHTS_STDIN;
*rights_inheriting = RIGHTS_STDIN;
return __WASI_ESUCCESS;
}

if (os_is_stdout_handle(fd)) {
*rights_base = RIGHTS_STDOUT;
*rights_inheriting = RIGHTS_STDOUT;
return __WASI_ESUCCESS;
}

if (os_is_stderr_handle(fd)) {
*rights_base = RIGHTS_STDERR;
*rights_inheriting = RIGHTS_STDERR;
return __WASI_ESUCCESS;
}

error = os_fstat(fd, &buf);
if (error != __WASI_ESUCCESS)
return error;
Expand Down Expand Up @@ -542,6 +524,21 @@ fd_determine_type_rights(os_file_handle fd, __wasi_filetype_t *type,
break;
}

if (os_is_stdin_handle(fd)) {
*rights_base = RIGHTS_STDIN;
*rights_inheriting = RIGHTS_STDIN;
}

if (os_is_stdout_handle(fd)) {
*rights_base = RIGHTS_STDOUT;
*rights_inheriting = RIGHTS_STDOUT;
}

if (os_is_stderr_handle(fd)) {
*rights_base = RIGHTS_STDERR;
*rights_inheriting = RIGHTS_STDERR;
}

return error;
}

Expand Down
Loading