mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
BUG/MINOR: worker: Missing calloc return value check in mworker_env_to_proc_list
A memory allocation failure happening in mworker_env_to_proc_list when trying to allocate a mworker_proc would have resulted in a crash. This function is only called during init. It was raised in GitHub issue #1233. It could be backported to all stable branches.
This commit is contained in:
parent
6443bcc2e1
commit
1f4fa906c7
@ -20,7 +20,7 @@
|
|||||||
extern struct mworker_proc *proc_self;
|
extern struct mworker_proc *proc_self;
|
||||||
|
|
||||||
void mworker_proc_list_to_env();
|
void mworker_proc_list_to_env();
|
||||||
void mworker_env_to_proc_list();
|
int mworker_env_to_proc_list();
|
||||||
|
|
||||||
|
|
||||||
void mworker_block_signals();
|
void mworker_block_signals();
|
||||||
|
@ -1892,8 +1892,10 @@ static void init(int argc, char **argv)
|
|||||||
if (global.mode & (MODE_MWORKER|MODE_MWORKER_WAIT)) {
|
if (global.mode & (MODE_MWORKER|MODE_MWORKER_WAIT)) {
|
||||||
struct wordlist *it, *c;
|
struct wordlist *it, *c;
|
||||||
|
|
||||||
mworker_env_to_proc_list(); /* get the info of the children in the env */
|
/* get the info of the children in the env */
|
||||||
|
if (mworker_env_to_proc_list() < 0) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if (!LIST_ISEMPTY(&mworker_cli_conf)) {
|
if (!LIST_ISEMPTY(&mworker_cli_conf)) {
|
||||||
|
|
||||||
|
@ -131,13 +131,13 @@ void mworker_proc_list_to_env()
|
|||||||
/*
|
/*
|
||||||
* unserialize the proc list from the environment
|
* unserialize the proc list from the environment
|
||||||
*/
|
*/
|
||||||
void mworker_env_to_proc_list()
|
int mworker_env_to_proc_list()
|
||||||
{
|
{
|
||||||
char *msg, *token = NULL, *s1;
|
char *msg, *token = NULL, *s1;
|
||||||
|
|
||||||
msg = getenv("HAPROXY_PROCESSES");
|
msg = getenv("HAPROXY_PROCESSES");
|
||||||
if (!msg)
|
if (!msg)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
while ((token = strtok_r(msg, "|", &s1))) {
|
while ((token = strtok_r(msg, "|", &s1))) {
|
||||||
struct mworker_proc *child;
|
struct mworker_proc *child;
|
||||||
@ -147,6 +147,10 @@ void mworker_env_to_proc_list()
|
|||||||
msg = NULL;
|
msg = NULL;
|
||||||
|
|
||||||
child = calloc(1, sizeof(*child));
|
child = calloc(1, sizeof(*child));
|
||||||
|
if (!child) {
|
||||||
|
ha_alert("Out of memory while trying to allocate a worker process structure.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
while ((subtoken = strtok_r(token, ";", &s2))) {
|
while ((subtoken = strtok_r(token, ";", &s2))) {
|
||||||
|
|
||||||
@ -193,6 +197,8 @@ void mworker_env_to_proc_list()
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsetenv("HAPROXY_PROCESSES");
|
unsetenv("HAPROXY_PROCESSES");
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Signal blocking and unblocking */
|
/* Signal blocking and unblocking */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user