From 4974b2b8119e8268eb7cababf82f2e7d84455f4a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 13 Dec 2013 14:31:27 -0800 Subject: [PATCH] ovs-thread: Fix crash by making count_cpu_count() return type a signed int. ofproto_set_threads() uses the calculation MAX(count_cpu_cores() - 2, 1) to decide on the default thread count. However, count_cpu_cores() returns 0 if it can't count the number of cores, or 1 if there's only one core, and that causes the calculation to come out as UINT_MAX-2 or UINT_MAX-1, respectively, which causes a memory allocation failure later. There are other ways to fix this problem, too, of course. Signed-off-by: Ben Pfaff --- lib/ovs-thread.c | 2 +- lib/ovs-thread.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c index dcaf7ff9a..aa3ad15b5 100644 --- a/lib/ovs-thread.c +++ b/lib/ovs-thread.c @@ -371,7 +371,7 @@ parse_cpuinfo(long int *n_cores) * Tries not to count hyper-threads, but may be inaccurate - particularly on * platforms that do not provide /proc/cpuinfo, but also if /proc/cpuinfo is * formatted different to the layout that parse_cpuinfo() expects. */ -unsigned int +int count_cpu_cores(void) { static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h index 1f2de72c8..b6d973f6e 100644 --- a/lib/ovs-thread.h +++ b/lib/ovs-thread.h @@ -505,6 +505,6 @@ bool may_fork(void); /* Useful functions related to threading. */ -unsigned int count_cpu_cores(void); +int count_cpu_cores(void); #endif /* ovs-thread.h */ -- 2.47.0