FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

src: fix UB in InternalModuleReadFile() by bnoordhuis · Pull Request #16871 · nodejs/node · GitHub

/ node Public

src: fix UB in InternalModuleReadFile() - #16871

Merged
bnoordhuis merged 0 commit into
nodejs:masterfrom
bnoordhuis:fix-module-ub
Nov 9, 2017
Merged

src: fix UB in InternalModuleReadFile()#16871
bnoordhuis merged 0 commit into
nodejs:masterfrom
bnoordhuis:fix-module-ub

Conversation

bnoordhuis commented Nov 7, 2017
edited
Loading

Copy link
Copy Markdown
Member

&vec[0] is undefined behavior when vec.size() == 0.

It is mostly academic because package.json files are not usually empty
and because with most STL implementations it decays to something that
is legal C++ as long as the result is not dereferenced, but better safe
than sorry.

Note that the tests don't actually fail because of that, I added them
as sanity checks.

Split off from #15767 where it already had a couple of LGTMs.

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

nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. labels Nov 7, 2017
Comment thread test/parallel/test-module-binding.js Outdated

jasnell Nov 8, 2017
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

unblocking nit: for consistency...

const fixtures = require('../common/fixtures');
/* ... */
strictEqual(internalModuleReadFile(fixtures.path('empty-with-bom.txt'));

Copy link
Copy Markdown
Member Author

Updated test. New CI: https://ci.nodejs.org/job/node-test-pull-request/11322/

bnoordhuis closed this Nov 9, 2017
bnoordhuis deleted the fix-module-ub branch November 9, 2017 11:59
bnoordhuis merged commit f823d38 into nodejs:master Nov 9, 2017
evanlucas pushed a commit that referenced this pull request Nov 13, 2017
`&vec[0]` is undefined behavior when `vec.size() == 0`.

It is mostly academic because package.json files are not usually empty
and because with most STL implementations it decays to something that
is legal C++ as long as the result is not dereferenced, but better safe
than sorry.

Note that the tests don't actually fail because of that, I added them
as sanity checks.

PR-URL: #16871
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas mentioned this pull request Nov 13, 2017

Copy link
Copy Markdown
Contributor

Should this land on v8.x or v6.x?

It lands cleanly on 8.x, but will require a backport for v6.x

Copy link
Copy Markdown
Member

@MylesBorins it’s not worth the trouble of backporting I’d say (not that I’d want to stop @bnoordhuis from doing that), but if it lands cleanly it should probably go into v8.x

gibfahn pushed a commit that referenced this pull request Dec 13, 2017
`&vec[0]` is undefined behavior when `vec.size() == 0`.

It is mostly academic because package.json files are not usually empty
and because with most STL implementations it decays to something that
is legal C++ as long as the result is not dereferenced, but better safe
than sorry.

Note that the tests don't actually fail because of that, I added them
as sanity checks.

PR-URL: #16871
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This was referenced Dec 20, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to 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++. fs Issues and PRs related to the fs subsystem / file system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL