From: Willy Tarreau Date: Mon, 15 Oct 2018 09:18:03 +0000 (+0200) Subject: BUILD: peers: check allocation error during peers_init_sync() X-Git-Tag: v1.9-dev4~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d944344f01d9ea914d94c45f6ac7c224c6143fc9;p=thirdparty%2Fhaproxy.git BUILD: peers: check allocation error during peers_init_sync() peers_init_sync() doesn't check task_new()'s return value and doesn't return any result to indicate success or failure. Let's make it return an int and check it from the caller. This can be backported as far as 1.6. --- diff --git a/include/proto/peers.h b/include/proto/peers.h index 782b66e4d2..9d4aaff232 100644 --- a/include/proto/peers.h +++ b/include/proto/peers.h @@ -28,7 +28,7 @@ #include #include -void peers_init_sync(struct peers *peers); +int peers_init_sync(struct peers *peers); void peers_register_table(struct peers *, struct stktable *table); void peers_setup_frontend(struct proxy *fe); diff --git a/src/cfgparse.c b/src/cfgparse.c index 1ca10bef27..5a6b705ef4 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -9085,7 +9085,12 @@ out_uri_auth_compat: curpeers->peers_fe = NULL; } else { - peers_init_sync(curpeers); + if (!peers_init_sync(curpeers)) { + ha_alert("Peers section '%s': out of memory, giving up on peers.\n", + curpeers->id); + cfgerr++; + break; + } last = &curpeers->next; continue; } diff --git a/src/peers.c b/src/peers.c index e61caaf93f..c16617d909 100644 --- a/src/peers.c +++ b/src/peers.c @@ -2202,9 +2202,9 @@ static struct task *process_peer_sync(struct task * task, void *context, unsigne /* - * + * returns 0 in case of error. */ -void peers_init_sync(struct peers *peers) +int peers_init_sync(struct peers *peers) { struct peer * curpeer; struct listener *listener; @@ -2216,10 +2216,14 @@ void peers_init_sync(struct peers *peers) list_for_each_entry(listener, &peers->peers_fe->conf.listeners, by_fe) listener->maxconn = peers->peers_fe->maxconn; peers->sync_task = task_new(MAX_THREADS_MASK); + if (!peers->sync_task) + return 0; + peers->sync_task->process = process_peer_sync; peers->sync_task->context = (void *)peers; peers->sighandler = signal_register_task(0, peers->sync_task, 0); task_wakeup(peers->sync_task, TASK_WOKEN_INIT); + return 1; }