From: Cyril Bonté Date: Wed, 6 Aug 2014 23:55:38 +0000 (+0200) Subject: BUG/MEDIUM: checks: segfault with external checks in a backend section X-Git-Tag: v1.6-dev1~340 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=99c5bf5ff4b07b1bc96e03591a6d5b2fbd816c3a;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: checks: segfault with external checks in a backend section The documentation indicates that external checks can be used in a backend section, but the code requires a listener to provide information in the script arguments. External checks were initialized lately, during the first check, leaving some variables uninitialized in such a scenario, which trigger the segfault when accessed to collect errors information. To prevent the segfault, currently we should initialize the external checks earlier, during the process initialiation itself and quit if the error occurs. This fix is specific to the 1.6 branch. --- diff --git a/src/checks.c b/src/checks.c index 2c9958acab..aad2037caa 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1627,7 +1627,7 @@ static int prepare_external_check(struct check *check) if (!check->argv[i]) goto err; - return 0; + return 1; err: if (check->envp) { free(check->envp[1]); @@ -1642,7 +1642,7 @@ err: check->argv = NULL; } Alert(err_fmt, px->id, s->id); - return -1; + return 0; } /* @@ -1667,12 +1667,6 @@ static int connect_proc_chk(struct task *t) int status; pid_t pid; - if (!check->argv) { - status = prepare_external_check(check); - if (status < 0) - return SN_ERR_RESOURCE; - } - status = SN_ERR_RESOURCE; block_sigchld(); @@ -2140,6 +2134,10 @@ int start_checks() { for (s = px->srv; s; s = s->next) { /* A task for the main check */ if (s->check.state & CHK_ST_CONFIGURED) { + if (s->check.type == PR_O2_EXT_CHK) { + if (!prepare_external_check(&s->check)) + return -1; + } if (!start_check_task(&s->check, mininter, nbcheck, srvpos)) return -1; srvpos++;