Skip to content

Commit ad0072a

Browse files
cjihrigtargos
authored andcommitted
os: don't use getCheckedFunction() in userInfo()
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. PR-URL: #22609 Refs: #22599 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent cb15017 commit ad0072a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/os.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const {
4040
getOSType: _getOSType,
4141
getPriority: _getPriority,
4242
getTotalMem,
43-
getUserInfo: _getUserInfo,
43+
getUserInfo,
4444
getUptime,
4545
isBigEndian,
4646
setPriority: _setPriority
@@ -64,7 +64,6 @@ const getHostname = getCheckedFunction(_getHostname);
6464
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
6565
const getOSRelease = getCheckedFunction(_getOSRelease);
6666
const getOSType = getCheckedFunction(_getOSType);
67-
const getUserInfo = getCheckedFunction(_getUserInfo);
6867

6968
getFreeMem[Symbol.toPrimitive] = () => getFreeMem();
7069
getHostname[Symbol.toPrimitive] = () => getHostname();
@@ -239,6 +238,19 @@ function getPriority(pid) {
239238
return priority;
240239
}
241240

241+
function userInfo(options) {
242+
if (typeof options !== 'object')
243+
options = null;
244+
245+
const ctx = {};
246+
const user = getUserInfo(options, ctx);
247+
248+
if (user === undefined)
249+
throw new ERR_SYSTEM_ERROR(ctx);
250+
251+
return user;
252+
}
253+
242254
module.exports = {
243255
arch,
244256
cpus,
@@ -255,7 +267,7 @@ module.exports = {
255267
tmpdir,
256268
totalmem: getTotalMem,
257269
type: getOSType,
258-
userInfo: getUserInfo,
270+
userInfo,
259271
uptime: getUptime,
260272

261273
// Deprecated APIs

0 commit comments

Comments
 (0)