Skip to content

Commit bafba0a

Browse files
committed
check invalid topology
1 parent 3f62c8d commit bafba0a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/freebsd/topology.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,27 @@ struct cpuinfo_freebsd_topology cpuinfo_freebsd_detect_topology(void) {
8484
cpuinfo_log_error("failed to parse topology_spec:%s",
8585
topology_spec);
8686
free(topology_spec);
87-
return topology;
87+
goto fail;
8888
}
8989
free(topology_spec);
9090
topology.cores = sysctl_int("kern.smp.cores");
9191
if (topology.cores == 0) {
92-
topology.packages = 0;
93-
return topology;
92+
goto fail;
9493
}
94+
if (topology.cores < topology.packages) {
95+
goto fail;
96+
}
9597
topology.threads_per_core = sysctl_int("kern.smp.threads_per_core");
9698
if (topology.threads_per_core == 0) {
97-
topology.packages = 0;
98-
return topology;
99+
goto fail;
99100
}
100101
cpuinfo_log_debug("freebsd topology: packages = %d, cores = %d, "
101102
"threads_per_core = %d",
102103
topology.packages, topology.cores,
103104
topology.threads_per_core);
104105
topology.threads = topology.threads_per_core * topology.cores;
105106
return topology;
107+
fail:
108+
topology.packages = 0;
109+
return topology;
106110
}

0 commit comments

Comments
 (0)