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

BSD platforms: Reject negative and zero KERN_FSCALE factors #1275

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions dragonflybsd/DragonFlyBSDMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
this->cpus = xRealloc(this->cpus, (super->existingCPUs + 1) * sizeof(CPUData));
}

len = sizeof(kernelFScale);
if (sysctlbyname("kern.fscale", &kernelFScale, &len, NULL, 0) == -1) {
len = sizeof(this->kernelFScale);
if (sysctlbyname("kern.fscale", &this->kernelFScale, &len, NULL, 0) == -1 || this->kernelFScale <= 0) {
//sane default for kernel provided CPU percentage scaling, at least on x86 machines, in case this sysctl call failed
kernelFScale = 2048;
this->kernelFScale = 2048;
}

this->kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, errbuf);
Expand Down
2 changes: 1 addition & 1 deletion freebsd/FreeBSDMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
}

len = sizeof(this->kernelFScale);
if (sysctlbyname("kern.fscale", &this->kernelFScale, &len, NULL, 0) == -1) {
if (sysctlbyname("kern.fscale", &this->kernelFScale, &len, NULL, 0) == -1 || this->kernelFScale <= 0) {
//sane default for kernel provided CPU percentage scaling, at least on x86 machines, in case this sysctl call failed
this->kernelFScale = 2048;
}
Expand Down
2 changes: 1 addition & 1 deletion netbsd/NetBSDMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
NetBSDMachine_updateCPUcount(this);

size = sizeof(this->fscale);
if (sysctl(fmib, 2, &this->fscale, &size, NULL, 0) < 0) {
if (sysctl(fmib, 2, &this->fscale, &size, NULL, 0) < 0 || this->fscale <= 0) {
CRT_fatalError("fscale sysctl call failed");
}

Expand Down
2 changes: 1 addition & 1 deletion openbsd/OpenBSDMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
OpenBSDProcessList_updateCPUcount(this);

size = sizeof(this->fscale);
if (sysctl(fmib, 2, &this->fscale, &size, NULL, 0) < 0) {
if (sysctl(fmib, 2, &this->fscale, &size, NULL, 0) < 0 || this->fscale <= 0) {
CRT_fatalError("fscale sysctl call failed");
}

Expand Down