Skip to content

os: don't use getCheckedFunction() in userInfo()

Rodrigo Muino Tomonari requested to merge github/fork/danbev/userInfo_issue into master

os.userInfo() takes an optional object as its first argument. getCheckedFunction() adds a context object to the argument list passed to the binding layer. The context object has the potential to confuse the binding layer, particularly if an error occurs. This commit makes userInfo() explicitly call into the binding layer with two arguments.

We ran into this issue when running node on OpenShift where the user ID will be assigned by OpenShift regardless what is specified in the DockerFile. This leads to the command os.userInfo() to fail with the following error:

sh-4.2$ node -p 'os.userInfo()'
node[99]: ../src/node_os.cc:364:void node::os::GetUserInfo(const
v8::FunctionCallbackInfo<v8::Value>&):
Assertion `(args.Length()) >= (2)' failed.
 1: 0x986d00 node::Abort() [node]
 2: 0x986df1  [node]
 3: 0x9f76ec  [node]
 4: 0xc07547  [node]
 5: 0xc08cad  [node]
 6: 0xc08d26 v8::internal::Builtin_HandleApiCall(int,
v8::internal::Object**, v8::internal::Isolate*) [node]
 7: 0x858ecf5c01d
Aborted

Using a command like whoami also fails:

sh-4.2$ id
uid=1000030000 gid=0(root) groups=0(root),1000030000

sh-4.2$ whoami
whoami: cannot find name for user ID 1000030000

The issue here is that we are not getting the libuv error as the check is prior to that. Debugging this we can see the errno:

sh-4.2$ gdb --args node -p 'os.userInfo()'
(gdb) br node_os.cc:364
Breakpoint 1 at 0x9f74b8: node_os.cc:364. (2 locations)
(gdb) r
(gdb) print err
$1 = -2
(gdb)  print uv_err_name($1)
$3 = 0x1655163 "ENOENT"

This commit changes the args check to check that the length is one instead of two.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

Merge request reports

Loading