Browse Source

crypto: make malloc failure check cross-platform

`malloc(0)` may return NULL on some platforms. Do not report
out-of-memory error unless `malloc` was passed a number greater than
`0`.

PR-URL: https://github.com/nodejs/node/pull/8352
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
v6.x
Rich Trott 8 years ago
committed by Jeremiah Senkpiel
parent
commit
49f996f4f6
  1. 2
      src/node_crypto.cc
  2. 5
      test/parallel/parallel.status

2
src/node_crypto.cc

@ -5368,7 +5368,7 @@ class RandomBytesRequest : public AsyncWrap {
error_(0), error_(0),
size_(size), size_(size),
data_(static_cast<char*>(node::Malloc(size))) { data_(static_cast<char*>(node::Malloc(size))) {
if (data() == nullptr) if (data() == nullptr && size > 0)
FatalError("node::RandomBytesRequest()", "Out of Memory"); FatalError("node::RandomBytesRequest()", "Out of Memory");
Wrap(object, this); Wrap(object, this);
} }

5
test/parallel/parallel.status

@ -27,11 +27,6 @@ test-debug-signal-cluster : PASS,FLAKY
test-fs-watch-enoent : FAIL, PASS test-fs-watch-enoent : FAIL, PASS
test-fs-watch-encoding : FAIL, PASS test-fs-watch-encoding : FAIL, PASS
# being worked under https://github.com/nodejs/node/pull/7564
test-async-wrap-post-did-throw : PASS, FLAKY
test-async-wrap-throw-from-callback : PASS, FLAKY
test-crypto-random : PASS, FLAKY
#being worked under https://github.com/nodejs/node/issues/7973 #being worked under https://github.com/nodejs/node/issues/7973
test-stdio-closed : PASS, FLAKY test-stdio-closed : PASS, FLAKY

Loading…
Cancel
Save