| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 51e09d0 commit 62e83b3
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -234,11 +234,13 @@ void* Realloc(void* pointer, size_t size) { | |||
| 234 | 234 | ||
| 235 | 235 | // As per spec realloc behaves like malloc if passed nullptr. | |
| 236 | 236 | void* Malloc(size_t size) { | |
| 237 | + if (size == 0) size = 1; | ||
| 237 | 238 | return Realloc(nullptr, size); | |
| 238 | 239 | } | |
| 239 | 240 | ||
| 240 | 241 | void* Calloc(size_t n, size_t size) { | |
| 241 | - if ((n == 0) || (size == 0)) return nullptr; | ||
| 242 | + if (n == 0) n = 1; | ||
| 243 | + if (size == 0) size = 1; | ||
| 242 | 244 | CHECK_GE(n * size, n); // Overflow guard. | |
| 243 | 245 | return calloc(n, size); | |
| 244 | 246 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,3 +74,17 @@ TEST(UtilTest, ToLower) { | |||
| 74 | 74 | EXPECT_EQ('a', ToLower('a')); | |
| 75 | 75 | EXPECT_EQ('a', ToLower('A')); | |
| 76 | 76 | } | |
| 77 | + | ||
| 78 | + TEST(UtilTest, Malloc) { | ||
| 79 | + using node::Malloc; | ||
| 80 | + EXPECT_NE(nullptr, Malloc(0)); | ||
| 81 | + EXPECT_NE(nullptr, Malloc(1)); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + TEST(UtilTest, Calloc) { | ||
| 85 | + using node::Calloc; | ||
| 86 | + EXPECT_NE(nullptr, Calloc(0, 0)); | ||
| 87 | + EXPECT_NE(nullptr, Calloc(1, 0)); | ||
| 88 | + EXPECT_NE(nullptr, Calloc(0, 1)); | ||
| 89 | + EXPECT_NE(nullptr, Calloc(1, 1)); | ||
| 90 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,3 +79,11 @@ assert.throws(function() { | |||
| 79 | 79 | assert.throws(function() { | |
| 80 | 80 | crypto.pbkdf2('password', 'salt', 1, -1, common.fail); | |
| 81 | 81 | }, /Bad key length/); | |
| 82 | + | ||
| 83 | + // Should not get FATAL ERROR with empty password and salt | ||
| 84 | + // https://github.com/nodejs/node/issues/8571 | ||
| 85 | + assert.doesNotThrow(() => { | ||
| 86 | + crypto.pbkdf2('', '', 1, 32, 'sha256', common.mustCall((e) => { | ||
| 87 | + assert.ifError(e); | ||
| 88 | + })); | ||
| 89 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments