Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e4fc3ab

Browse filesBrowse files
bnoordhuisjuanarbol
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 574afac commit e4fc3ab
Copy full SHA for e4fc3ab

File tree

Expand file treeCollapse file tree

1 file changed

+4
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-3
lines changed
Open diff view settings
Collapse file

‎src/process_wrap.cc‎

Copy file name to clipboardExpand all lines: src/process_wrap.cc
+4-3Lines changed: 4 additions & 3 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.