Skip to content

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

Closed
@jakepetroules

Description

@jakepetroules

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]?

Metadata

Metadata

Assignees

Labels

blockerShow stopping issues for 0.0.1bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions