Skip to content
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

test: assume priv ports start at 1024 if it can't be changed #46536

Merged
merged 3 commits into from
Mar 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update to remove TOCTOU stat-then-open pattern
  • Loading branch information
Kevin Lentin committed Feb 7, 2023
commit a5017cf1705b411e02ca38ad4d2904bc92bf015a
12 changes: 7 additions & 5 deletions test/parallel/test-cluster-bind-privileged-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');
const { readFileSync, statSync } = require('fs');
const { readFileSync } = require('fs');

if (common.isLinux) {
const procFileName = '/proc/sys/net/ipv4/ip_unprivileged_port_start';
// Does not exist for Kernel < 4.1 where answer is 1024. So only test limit if limit exists
if (statSync(procFileName, { throwIfNoEntry: false })) {
const unprivilegedPortStart = parseInt(readFileSync(procFileName));
try {
const sysctlOutput = execSync('sysctl net.ipv4.ip_unprivileged_port_start').toString();
Copy link
Member

@lpinca lpinca Feb 8, 2023

Choose a reason for hiding this comment

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

This basically reverts f69e84c. Can't you simply handle the error thrown by readFileSync('/proc/sys/net/ipv4/ip_unprivileged_port_start') when the file does not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that is so embarrassing. I am doing this in v19 and v18 (the one I'm actually trying to deploy). Went back to the old one. Ignore this. Will fix in next few hours. ARGGHHH

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, fixed. Needed more coffee. Working in 3 places (v19 source, v18 source, my build).

const unprivilegedPortStart = parseInt(sysctlOutput.split(' ')[2], 10);
if (unprivilegedPortStart <= 42) {
common.skip('Port 42 is unprivileged');
}
} catch {
// Do nothing, feature doesn't exist, minimum is 1024 so 42 is usable.
// Continue...
}
}

Expand Down