Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 124a0f2

Browse files
zcbenzkevinsawicki
authored andcommitted
Guard against NULL returned by uv_err_name.
The uv_err_name would return NULL on unknown system error, which then would crash V8 by creating string from NULL.
1 parent 693b350 commit 124a0f2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/node.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,11 @@ Local<Value> UVException(Isolate* isolate,
941941
if (!msg || !msg[0])
942942
msg = uv_strerror(errorno);
943943

944-
Local<String> js_code = OneByteString(isolate, uv_err_name(errorno));
944+
const char* err_name = uv_err_name(errorno);
945+
if (err_name == NULL)
946+
err_name = "UnknownSystemError";
947+
948+
Local<String> js_code = OneByteString(isolate, err_name);
945949
Local<String> js_syscall = OneByteString(isolate, syscall);
946950
Local<String> js_path;
947951
Local<String> js_dest;

src/uv.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void ErrName(const FunctionCallbackInfo<Value>& args) {
4141
if (err >= 0)
4242
return env->ThrowError("err >= 0");
4343
const char* name = uv_err_name(err);
44+
if (name == NULL)
45+
name = "UnknownSystemError";
4446
args.GetReturnValue().Set(OneByteString(env->isolate(), name));
4547
}
4648

0 commit comments

Comments
 (0)