Skip to content

Wrong file descriptor passed to _subprocess_fork_exec in Linux prefork path? #52

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
jakepetroules opened this issue Jun 1, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@jakepetroules
Copy link
Contributor

jakepetroules commented Jun 1, 2025

Note the following code in Subprocess+Linux.swift:

// Setup input
let fileDescriptors: [CInt] = [
    inputReadFileDescriptor?.platformDescriptor() ?? -1,
    inputWriteFileDescriptor?.platformDescriptor() ?? -1,
    outputWriteFileDescriptor?.platformDescriptor() ?? -1,
    outputReadFileDescriptor?.platformDescriptor() ?? -1,

    // repeated twice
    errorWriteFileDescriptor?.platformDescriptor() ?? -1,
    errorWriteFileDescriptor?.platformDescriptor() ?? -1,
]

Here, errorWriteFileDescriptor is passed twice, but fileDescriptors[5] is never accessed anywhere in the codebase.

Additionally, file_descriptors[4] is both dup'ed and closed.

    if (file_descriptors[1] >= 0) {
      rc = close(file_descriptors[1]);
    }
    if (file_descriptors[3] >= 0) {
      rc = close(file_descriptors[3]);
    }
    if (file_descriptors[4] >= 0) {
      rc = close(file_descriptors[4]);
    }

Was the close code meant to refer to file_descriptors[5], and it just happens to work because the same value is always passed for [4] and [5]?

@jakepetroules jakepetroules added the bug Something isn't working label Jun 1, 2025
@iCharlesHu
Copy link
Contributor

Ahh good catch thanks!

@iCharlesHu iCharlesHu self-assigned this Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants