Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 16c9e8e

Browse files
committed
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 97c6e17 commit 16c9e8e

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
@@ -818,7 +818,11 @@ Local<Value> UVException(Isolate* isolate,
818818
if (!msg || !msg[0])
819819
msg = uv_strerror(errorno);
820820

821-
Local<String> js_code = OneByteString(isolate, uv_err_name(errorno));
821+
const char* err_name = uv_err_name(errorno);
822+
if (err_name == NULL)
823+
err_name = "UnknownSystemError";
824+
825+
Local<String> js_code = OneByteString(isolate, err_name);
822826
Local<String> js_syscall = OneByteString(isolate, syscall);
823827
Local<String> js_path;
824828
Local<String> js_dest;

src/uv.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ void ErrName(const FunctionCallbackInfo<Value>& args) {
2222
if (err >= 0)
2323
return env->ThrowError("err >= 0");
2424
const char* name = uv_err_name(err);
25+
if (name == NULL)
26+
name = "UnknownSystemError";
2527
args.GetReturnValue().Set(OneByteString(env->isolate(), name));
2628
}
2729

0 commit comments

Comments
 (0)