Skip to content

crypto: make malloc failure check cross-platform - #8352

Closed
Trott wants to merge 1 commit into
nodejs:masterfrom
Trott:aix-fix
Closed

crypto: make malloc failure check cross-platform#8352
Trott wants to merge 1 commit into
nodejs:masterfrom
Trott:aix-fix

Conversation

@Trott

Copy link
Copy Markdown
Member
Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

crypto

Description of change

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

Marking as in progress for the moment. This is an attempt to fix some of the perma-flaky tests on AIX.

@TrottTrott added wip Issues and PRs that are still a work in progress. crypto Issues and PRs related to the crypto subsystem. labels Aug 31, 2016
@nodejs-github-botnodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Aug 31, 2016
@Trott

Copy link
Copy Markdown
MemberAuthor

@Trott

Copy link
Copy Markdown
MemberAuthor

This seems to work. Removing in progress label. /cc @mhdawson @nodejs/crypto

Hopefully this is an acceptable short term workaround if it is not acceptable as a permanent fix.

Guess I better start looking around the code to see if anything bad could happen to that null pointer...

@TrottTrott removed the wip Issues and PRs that are still a work in progress. label Aug 31, 2016
`malloc(0)` may return NULL on some platforms. Do not report
out-of-memory error unless `malloc` was passed a number greater than
`0`.
Fixes: nodejs#7564
PR-URL: nodejs#8352
@Trott

Copy link
Copy Markdown
MemberAuthor

Fixes three of the four current perma-flaky tests on AIX. SmartOS failure looks unrelated.

CI again: https://ci.nodejs.org/job/node-test-pull-request/3901/

@bnoordhuis

Copy link
Copy Markdown
Member

See also #7564. I wasn't very happy with that approach but, mea culpa, I didn't get around to posting the alternative solution I talked about. I suppose any fix is better than no fix at this point.

@indutny

Copy link
Copy Markdown
Member

LGTM, if it works

@addaleax

Copy link
Copy Markdown
Member

LGTM

1 similar comment
@jasnell

Copy link
Copy Markdown
Member

LGTM

@mhdawson

mhdawson commented Aug 31, 2016

Copy link
Copy Markdown
Member

I'd prefer to land #7564 as it addresses the general problem as opposed to the specific problem that this patch addresses. However, I'm not opposed to landing this as well as it would be better not to depend on the platform specific malloc(0) behavior in this specific case.

So LTGM to land this but @bnoordhuis can you also give me an LTGM on #7564 as well so that I could land it.

@Trott

Trott commented Sep 1, 2016

Copy link
Copy Markdown
MemberAuthor

Would I be correct to infer that folks providing LGTM comments are affirming that they believe using the null pointer will have no detrimental effects on security or stability? (That's my opinion, but I don't trust myself to analyze C++ crypto code, so I'm looking for specific external validation on this.)

@addaleax

Copy link
Copy Markdown
Member

@Trott Yes, using nullptr for a zero-length Buffer should be okay. We’re definitely having tests to make sure that that works. :)

@mhdawson

Copy link
Copy Markdown
Member

Based on the way that @bnoordhuis suggested that I change the implementation we'll need this fix as it moves all platforms so that we'll consistently get a nullptr for malloc(0).

To be able to test I cherry picked this across/resolved merge issues so might make sense to land them together. Just about to push 2 commits to #7564 and then do a CI run to make sure all it ok across platforms.

mhdawson pushed a commit to mhdawson/io.js that referenced this pull request Sep 1, 2016
`malloc(0)` may return NULL on some platforms. Do not report
out-of-memory error unless `malloc` was passed a number greater than
`0`.
Fixes: nodejs#7564
PR-URL: nodejs#8352
mhdawson pushed a commit that referenced this pull request Sep 6, 2016
`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: #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>
@mhdawson

Copy link
Copy Markdown
Member

Landed as ed640ae

@mhdawsonmhdawson closed this Sep 6, 2016
@Fishrock123Fishrock123 mentioned this pull request Sep 6, 2016
Fishrock123 pushed a commit that referenced this pull request Sep 9, 2016
`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: #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>
Fishrock123 pushed a commit that referenced this pull request Sep 9, 2016
`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: #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>
@MylesBorins

Copy link
Copy Markdown
Contributor

@mhdawson should this be backported?

@MylesBorins

MylesBorins commented Oct 11, 2016

Copy link
Copy Markdown
Contributor

@Trott backport?

edit: does not land cleanly

@Trott

Copy link
Copy Markdown
MemberAuthor

@thealphanerd I believe it is only needed if and only if https://github.com/nodejs/node/commit/a00ccb0fb9eb716925058b0a20fcec9251de3309/ / #7564 lands. That PR is currently marked as "do not land" so I think this too should be marked that way.

@mhdawson

Copy link
Copy Markdown
Member

Agreed.

@Trott
Trott deleted the aix-fix branch January 13, 2022 22:44
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.cryptoIssues and PRs related to the crypto subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@Trott@bnoordhuis@indutny@addaleax@jasnell@mhdawson@MylesBorins@nodejs-github-bot