From ac2412fee8fd561885a9bb6a91ab2ae1f1b948c9 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 16 Jan 2020 15:55:19 +0100 Subject: [PATCH] MINOR: config: Use dedicated function to parse proxy's errorloc The parsing of the "errorloc" directive is now handled by the function http_parse_errorloc(). --- src/cfgparse-listen.c | 46 +++++++++++-------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 418de0f2a6..b42fe536d8 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -3810,51 +3810,29 @@ stats_error_parsing: else if (!strcmp(args[0], "errorloc") || !strcmp(args[0], "errorloc302") || !strcmp(args[0], "errorloc303")) { /* error location */ - int errnum, errlen; - char *err; + struct buffer chk; + int errloc, status, rc; if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) err_code |= ERR_WARN; - if (*(args[2]) == 0) { + if (*(args[1]) == 0 || *(args[2]) == 0) { ha_alert("parsing [%s:%d] : <%s> expects and as arguments.\n", file, linenum, args[0]); err_code |= ERR_ALERT | ERR_FATAL; goto out; } - errnum = atol(args[1]); - if (!strcmp(args[0], "errorloc303")) { - errlen = strlen(HTTP_303) + strlen(args[2]) + 5; - err = malloc(errlen); - errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_303, args[2]); - } else { - errlen = strlen(HTTP_302) + strlen(args[2]) + 5; - err = malloc(errlen); - errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_302, args[2]); - } - - for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { - if (http_err_codes[rc] == errnum) { - struct buffer chk; - - if (!http_str_to_htx(&chk, ist2(err, errlen))) { - ha_alert("parsing [%s:%d] : unable to convert message in HTX for HTTP return code %d.\n", - file, linenum, http_err_codes[rc]); - err_code |= ERR_ALERT | ERR_FATAL; - free(err); - goto out; - } - chunk_destroy(&curproxy->errmsg[rc]); - curproxy->errmsg[rc] = chk; - break; - } + status = atol(args[1]); + errloc = (!strcmp(args[0], "errorloc303") ? 303 : 302); + rc = http_parse_errorloc(errloc, status, args[2], &chk, &errmsg); + if (rc == -1) { + ha_alert("parsing [%s:%d] : %s: %s\n", file, linenum, args[0], errmsg); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; } - if (rc >= HTTP_ERR_SIZE) { - ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", - file, linenum, errnum, args[0]); - free(err); - } + chunk_destroy(&curproxy->errmsg[rc]); + curproxy->errmsg[rc] = chk; } else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ struct buffer chk; -- 2.47.3