• Lambros Lambrou's avatar
    [remoting] Reopen stdin/stdout after creating PipeMessagingChannel. · ca76b6e6
    Lambros Lambrou authored
    PipeMessagingChannel takes ownership of the passed File objects,
    closing them. This means that stdin/stdout are closed, to prevent
    accidental corruption of the native-messaging streams.
    
    This CL reopens stdin/stdout against /dev/null, which protects them,
    preventing any future calls to POSIX open() returning these descriptors.
    For example, LaunchProcess (by default) treats FDs 0, 1, 2 specially
    (it closes all descriptors except them), so having stdin/stdout directed
    to some random file could cause unintended effects.
    
    This CL also fixes PipeMessagingChannel ctor to not interleave the dup()
    and close() calls:
    dup, dup, close, close
    instead of
    dup, close, dup, close
    so that the second dup() call now returns a high-numbered descriptor
    instead of 0 (freed up by first close() call).
    
    Bug: 1029858
    Change-Id: I209f5734a06216323c54a680852b381fb6f2f96b
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1947397
    Commit-Queue: Lambros Lambrou <lambroslambrou@chromium.org>
    Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
    Auto-Submit: Lambros Lambrou <lambroslambrou@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#720768}
    ca76b6e6
pipe_messaging_channel.h 2.83 KB