mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
src: fix UB in overflow checks
Refs: https://github.com/nodejs/node/issues/45868 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
27d3201502
commit
4454f5fd71
1 file changed
+4
-3
+4
-3
@@ -24,8 +24,9 @@
|
||||
#include "stream_wrap.h"
|
||||
#include "util-inl.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <climits>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace node {
|
||||
|
||||
@@ -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];
|
||||
@@ -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(),
|
||||
|
||||
Reference in new issue
Block a user