Skip to content

Commit

Permalink
src: fix UB in overflow checks
Browse files Browse the repository at this point in the history
Refs: #45868
PR-URL: #45882
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
bnoordhuis authored Dec 20, 2022
1 parent 95200ba commit 5124613
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/process_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#include "stream_wrap.h"
#include "util-inl.h"

#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstring>

namespace node {

Expand Down Expand Up @@ -190,7 +191,7 @@ class ProcessWrap : public HandleWrap {
if (!argv_v.IsEmpty() && argv_v->IsArray()) {
Local<Array> js_argv = argv_v.As<Array>();
int argc = js_argv->Length();
CHECK_GT(argc + 1, 0); // Check for overflow.
CHECK_LT(argc, INT_MAX); // Check for overflow.

// Heap allocate to detect errors. +1 is for nullptr.
options.args = new char*[argc + 1];
Expand Down Expand Up @@ -218,7 +219,7 @@ class ProcessWrap : public HandleWrap {
if (!env_v.IsEmpty() && env_v->IsArray()) {
Local<Array> env_opt = env_v.As<Array>();
int envc = env_opt->Length();
CHECK_GT(envc + 1, 0); // Check for overflow.
CHECK_LT(envc, INT_MAX); // Check for overflow.
options.env = new char*[envc + 1]; // Heap allocated to detect errors.
for (int i = 0; i < envc; i++) {
node::Utf8Value pair(env->isolate(),
Expand Down

0 comments on commit 5124613

Please sign in to comment.