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 — net: prevent /32 ipv4 mask from matching all ips by supriyo-biswas · Pull Request #43381 · nodejs/node

Conversation

@supriyo-biswas

@supriyo-biswas supriyo-biswas commented Jun 11, 2022

Copy link
Copy Markdown
Contributor

Fixes: #43360

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss, sntwandy, and jasnell reacted with thumbs up emoji
All reactions
  • 👍 3 reactions
@nodejs-github-bot

nodejs-github-bot commented Jun 11, 2022

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jun 11, 2022
@nodejs-github-bot

nodejs-github-bot commented Jun 11, 2022

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina reviewed Jun 11, 2022
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good work!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sntwandy reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread test/parallel/test-blocklist.js Outdated

@mcollina mcollina Jun 11, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

See the linter issue, capitalize the comment

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@supriyo-biswas
supriyo-biswas force-pushed the ipv4-32-subnet-mask branch 2 times, most recently from fbeb91a to 539c715 Compare June 11, 2022 15:47
bnoordhuis
bnoordhuis reviewed Jun 12, 2022
View reviewed changes
Comment thread src/node_sockaddr.cc Outdated
Comment on lines 218 to 221

@bnoordhuis bnoordhuis Jun 12, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Not that your fix is wrong but the mask calculation has undefined behavior (signed out-of-range shift) for prefix > 30 so a more comprehensive fix is this:

Suggested change
if (prefix == 32)
return compare_ipv4(ip, net) == SocketAddress::CompareResult::SAME;
uint32_t mask = ((1 << prefix) - 1) << (32 - prefix);
uint32_t mask = ((1ull << prefix) - 1) << (32 - prefix);

There's another instance around line 296.

prefix arguably shouldn't be an int but e.g. a uint8_t because what does a less-than-zero prefix even mean? That's a bigger change though.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@supriyo-biswas supriyo-biswas Jun 13, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

While I agree with your observation, currently there is a check around prefixes < 0 or > 32:

$ ~/node/bin/node 
> const bl = new net.BlockList()
undefined
> bl.addSubnet('1.1.0.0', -1, 'ipv4')
Uncaught:
RangeError [ERR_OUT_OF_RANGE]: The value of "prefix" is out of range. It must be >= 0 && <= 32. Received -1
    at __node_internal_captureLargerStackTrace (node:internal/errors:477:5)
    at new NodeError (node:internal/errors:388:5)
    at __node_internal_ (node:internal/validators:92:13)
    at BlockList.addSubnet (node:internal/blocklist:107:9) {
  code: 'ERR_OUT_OF_RANGE'
}

If you still feel that this is required, please let me know.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Jun 13, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That's right, and there are also a couple of additional C++ checks that enforce the range but still, switching to uint8_t would help code clarity. That's just a suggestion though, not a hard requirement for this PR to land.

The UB should be fixed though. It's dangerous.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@supriyo-biswas supriyo-biswas Jun 14, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Apologies for the delay on this. What is the recommended approach to add the UB fix on top, should be a separate commit or should the previous commit be amended with the fix?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Jun 14, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Doesn't matter, what you prefer. It gets squashed into a single commit before merge anyway.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot mentioned this pull request Jun 14, 2022
CI Reliability 2022-06-14 nodejs/reliability#300
Open
16 tasks
mcollina
mcollina approved these changes Jun 15, 2022
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@supriyo-biswas
net: prevent /32 ipv4 mask from matching all ips
292d933
Fixes: nodejs#43360
@supriyo-biswas
supriyo-biswas force-pushed the ipv4-32-subnet-mask branch from 539c715 to 292d933 Compare June 15, 2022 17:41
@supriyo-biswas

supriyo-biswas commented Jun 15, 2022

Copy link
Copy Markdown
Contributor Author

Added the UB check as @bnoordhuis suggested.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnoordhuis
bnoordhuis reviewed Jun 15, 2022
View reviewed changes
Comment thread src/node_sockaddr.cc Resolved

Uh oh!

There was an error while loading. Please reload this page.

@supriyo-biswas @bnoordhuis
Update src/node_sockaddr.cc
d7dd5db
Co-authored-by: Ben Noordhuis <[email protected]>
@tniessen tniessen added the commit-queue-squash PRs the Commit Queue should land as one squashed commit. label Jun 16, 2022
@nodejs-github-bot

nodejs-github-bot commented Jun 19, 2022

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jun 20, 2022
CI Reliability 2022-06-20 nodejs/reliability#306
Open
CI Reliability 2022-06-21 nodejs/reliability#307
Open
CI Reliability 2022-06-22 nodejs/reliability#308
Open
CI Reliability 2022-06-23 nodejs/reliability#309
Open
lpinca
lpinca approved these changes Jun 23, 2022
View reviewed changes
@lpinca lpinca added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Jun 23, 2022
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Jun 23, 2022
@nodejs-github-bot

nodejs-github-bot commented Jun 23, 2022

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jun 24, 2022
CI Reliability 2022-06-24 nodejs/reliability#310
Open
32 tasks
@nodejs-github-bot

nodejs-github-bot commented Jun 24, 2022

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Jun 24, 2022

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jun 25, 2022
CI Reliability 2022-06-25 nodejs/reliability#311
Open
32 tasks
@mcollina mcollina removed the needs-ci PRs that need a full CI run. label Jun 25, 2022
@mcollina mcollina added the commit-queue PRs queued for automated landing through the Commit Queue. label Jun 25, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Jun 25, 2022
@nodejs-github-bot
nodejs-github-bot merged commit b6bc44f into nodejs:main Jun 25, 2022
@nodejs-github-bot

nodejs-github-bot commented Jun 25, 2022

Copy link
Copy Markdown
Collaborator

Landed in b6bc44f

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jun 26, 2022
CI Reliability 2022-06-26 nodejs/reliability#312
Open
CI Reliability 2022-06-27 nodejs/reliability#313
Open
CI Reliability 2022-06-28 nodejs/reliability#314
Open
targos pushed a commit that referenced this pull request Jul 12, 2022
@supriyo-biswas @targos
net: prevent /32 ipv4 mask from matching all ips
f8bdc53
Fixes: #43360

PR-URL: #43381
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@targos targos mentioned this pull request Jul 12, 2022
v18.6.0 release proposal #43789
Merged
targos pushed a commit that referenced this pull request Jul 20, 2022
@supriyo-biswas @targos
net: prevent /32 ipv4 mask from matching all ips
b8d36e5
Fixes: #43360

PR-URL: #43381
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
targos pushed a commit that referenced this pull request Jul 31, 2022
@supriyo-biswas @targos
net: prevent /32 ipv4 mask from matching all ips
265810a
Fixes: #43360

PR-URL: #43381
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@targos targos mentioned this pull request Aug 3, 2022
v16.17.0 release proposal #44098
Merged
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
@supriyo-biswas @guangwong
net: prevent /32 ipv4 mask from matching all ips
39a83eb
Fixes: nodejs/node#43360

PR-URL: nodejs/node#43381
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bnoordhuis bnoordhuis bnoordhuis left review comments
@mcollina mcollina mcollina approved these changes
@lpinca lpinca lpinca approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash PRs the Commit Queue should land as one squashed commit.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

/32 subnet mask erroneously matches all IP addresses

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@supriyo-biswas @nodejs-github-bot @mcollina @bnoordhuis @lpinca @tniessen
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — 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.