-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
os: fix netmask format check condition in getCIDR function #57324
base: main
Are you sure you want to change the base?
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 |
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.