Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: avoid crash using uv.errname() binding #44401

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/uv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ void ErrName(const FunctionCallbackInfo<Value>& args) {
"DEP0119").IsNothing())
return;
}
int err;
if (!args[0]->Int32Value(env->context()).To(&err)) return;
CHECK_LT(err, 0);
if (args[0]->IsNullOrUndefined()) {
return args.GetReturnValue().SetUndefined();
}
const int err = args[0].As<v8::Int32>()->Value();
const char* name = uv_err_name(err);
juanarbol marked this conversation as resolved.
Show resolved Hide resolved
args.GetReturnValue().Set(OneByteString(env->isolate(), name));
}
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-uv-errno.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@ function runTest(fn) {
`Received ${err}`
});
});

}

function errNameTest(fn) {
// uv.errname should not cause crash with invalid args
juanarbol marked this conversation as resolved.
Show resolved Hide resolved
[0, 1, 2, NaN, {}, false].forEach((err) => {
assert.match(fn(err), /Unknown system error/);
});

// uv.errname should return undefined with null or undefined args
[null, undefined].forEach((err) => {
assert.strictEqual(fn(err), undefined);
});
}

runTest(_errnoException);
runTest(getSystemErrorName);
errNameTest(uv.errname);