GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: Malloc/Calloc size 0 returns non-null pointer · nodejs/node@62e83b3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • util-inl.h
  • test
    • cctest
      • util.cc
    • parallel
      • test-crypto-pbkdf2.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/util-inl.h‎

Copy file name to clipboardExpand all lines: src/util-inl.h
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,13 @@ void* Realloc(void* pointer, size_t size) {
234234

235235
// As per spec realloc behaves like malloc if passed nullptr.
236236
void* Malloc(size_t size) {
237+
if (size == 0) size = 1;
237238
return Realloc(nullptr, size);
238239
}
239240

240241
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;
242244
CHECK_GE(n * size, n); // Overflow guard.
243245
return calloc(n, size);
244246
}
Collapse file

‎test/cctest/util.cc‎

Copy file name to clipboardExpand all lines: test/cctest/util.cc
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,17 @@ TEST(UtilTest, ToLower) {
7474
EXPECT_EQ('a', ToLower('a'));
7575
EXPECT_EQ('a', ToLower('A'));
7676
}
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+
}
Collapse file

‎test/parallel/test-crypto-pbkdf2.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-pbkdf2.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,11 @@ assert.throws(function() {
7979
assert.throws(function() {
8080
crypto.pbkdf2('password', 'salt', 1, -1, common.fail);
8181
}, /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+
});

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.