Skip to content

spawnSync's SyncProcessRunner::CopyJsStringArray segfaults with bad getter #9821

@deian

Description

@deian
  • Version:
  • Platform:
  • Subsystem:

Similar to #9820, the underlying binding code that is used by spawnSync can
segfault when called with objects/array that have "evil" getters/setters. The
following code shows an example of this:

const spawn_sync = process.binding('spawn_sync');

// compute envPairs as done by child_process
let envPairs = [];
for (var key in process.env) {
  envPairs.push(key + '=' + process.env[key]);
}

// mess with args
const args = [ '-a' ];

Object.defineProperty(args, 1, {
  get: () => { 
    return 3; // causes StringBytes::Write in spawn_sync.cc:986 to segfault since it's not a string
  },
  set: () => {
    // override so Set after Clone will do nothing because of this
  },
  enumerable: true
});


const options = {
  file: 'ls',
  args: args,
  envPairs: envPairs,
  stdio: [
    { type: 'pipe', readable: true, writable: false },
    { type: 'pipe', readable: false, writable: true },
    { type: 'pipe', readable: false, writable: true } 
  ]

};
spawn_sync.spawn(options);

May be worth again ensuring that all arguments are strings before calling into
the binding code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions