Skip to content

Commit 4454f5f

Browse files
bnoordhuisRafaelGSS
authored andcommitted
src: fix UB in overflow checks
Refs: #45868 PR-URL: #45882 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 27d3201 commit 4454f5f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/process_wrap.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
#include "stream_wrap.h"
2525
#include "util-inl.h"
2626

27-
#include <cstring>
27+
#include <climits>
2828
#include <cstdlib>
29+
#include <cstring>
2930

3031
namespace node {
3132

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

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

0 commit comments

Comments
 (0)