-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
os: fix netmask format check condition in getCIDR function #57324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Modified to check the format of the netmask instead of just checking that each part of the netmask is even
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57324 +/- ##
==========================================
+ Coverage 90.20% 90.22% +0.01%
==========================================
Files 630 630
Lines 185166 185203 +37
Branches 36227 36247 +20
==========================================
+ Hits 167036 167102 +66
+ Misses 11117 11044 -73
- Partials 7013 7057 +44
🚀 New features to boost your workflow:
|
Can you please add a test? |
@lpinca This function is only being used by networkInterfaces, which is getting it from internalBinding. Since networkInterfaces is not a pure function and returns a value based on the current state of the system, is there any way to do mocking or something in this regard? If you have any references or know how to do it, I'd appreciate it :) function networkInterfaces() {
const data = getInterfaceAddresses();
const result = {};
if (data === undefined)
return result;
for (let i = 0; i < data.length; i += 7) {
const name = data[i];
const entry = {
address: data[i + 1],
netmask: data[i + 2],
family: data[i + 3],
mac: data[i + 4],
internal: data[i + 5],
cidr: getCIDR(data[i + 1], data[i + 2], data[i + 3]),
};
const scopeid = data[i + 6];
if (scopeid !== -1)
entry.scopeid = scopeid;
const existing = result[name];
if (existing !== undefined)
ArrayPrototypePush(existing, entry);
else
result[name] = [entry];
}
return result;
} |
What do think about moving it to |
move to util/internal and add getCIDR function test file to test the getCIDR function and added test code for the part that checks the format of the subnetmask
@lpinca Sounds like a good idea, I moved the |
This comment was marked as outdated.
This comment was marked as outdated.
@lpinca PR seems to have stopped here, what should I do? |
This comment was marked as outdated.
This comment was marked as outdated.
Commit Queue failed- Loading data for nodejs/node/pull/57324 ✔ Done loading data for nodejs/node/pull/57324 ----------------------------------- PR info ------------------------------------ Title os: fix netmask format check condition in getCIDR function (#57324) Author Wiyeong Seo <[email protected]> (@HBSPS) Branch HBSPS:os-getCIDR -> nodejs:main Labels os, needs-ci Commits 2 - os: fix netmask format check condition in getCIDR function - test: move getCIDR function to internal/util and add test code Committers 1 - HBSPS <[email protected]> PR-URL: https://github.com/nodejs/node/pull/57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> -------------------------------------------------------------------------------- ℹ This PR was created on Wed, 05 Mar 2025 02:44:05 GMT ✔ Approvals: 2 ✔ - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/57324#pullrequestreview-2669497839 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/57324#pullrequestreview-2780071018 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2025-04-19T21:27:46Z: https://ci.nodejs.org/job/node-test-pull-request/66371/ - Querying data for job/node-test-pull-request/66371/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 57324 From https://github.com/nodejs/node * branch refs/pull/57324/merge -> FETCH_HEAD ✔ Fetched commits as 25842c5e35ef..6e529a46153e -------------------------------------------------------------------------------- [main c2a5b7fda5] os: fix netmask format check condition in getCIDR function Author: HBSPS <[email protected]> Date: Tue Mar 4 20:27:46 2025 -0600 1 file changed, 2 insertions(+), 1 deletion(-) Auto-merging lib/internal/util.js [main dd12864109] test: move getCIDR function to internal/util and add test code Author: HBSPS <[email protected]> Date: Sun Mar 9 13:36:08 2025 -0500 3 files changed, 81 insertions(+), 56 deletions(-) create mode 100644 test/parallel/test-internal-util-getCIDR.js ✔ Patches applied There are 2 commits in the PR. Attempting autorebase. Rebasing (2/4) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- os: fix netmask format check condition in getCIDR functionhttps://github.com/nodejs/node/actions/runs/14556471756 |
Landed in 7102ea1 |
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even PR-URL: #57324 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Modified to check the format of the netmask instead of just checking that each part of the netmask is even number.
(Ref: https://www.rfc-editor.org/rfc/rfc1878)
The result of the previous run was like this.
This does not satisfy the condition in netmask, but it passes the conditional statement and returns an invalid value.
I'm not sure if that conditional is necessary(if the correct value is always passed, etc), but I think it's doing the wrong thing, so I've modified it to look like this.
I modified the netmask to check if it satisfies the condition of containing '01', such as 11110010, since a 0 cannot be followed by a 1 according to the rules of netmask.
The benchmark results for changing conditions are shown below.