From 59fd51155595d6e3c37db8e4ee4bc5b2569a821d Mon Sep 17 00:00:00 2001 From: "Thierry FOURNIER / OZON.IO" Date: Tue, 22 Nov 2016 23:50:02 +0100 Subject: [PATCH] MEDIUM: log-format/conf: take into account the parse_logformat_string() return code This patch takes into account the return code of the parse_logformat_string() function. Now the configuration parser will fail if the log_format is not strict. --- src/cfgparse.c | 26 +++++++++---- src/proto_http.c | 98 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 83 insertions(+), 41 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index e4bbfcc9e..a355aa91c 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -7788,7 +7788,10 @@ int check_config_validity() */ pxname = rule->be.name; LIST_INIT(&rule->be.expr); - parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR); + if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR)) { + cfgerr++; + continue; + } node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); if (!LIST_ISEMPTY(&rule->be.expr)) { @@ -8272,8 +8275,10 @@ out_uri_auth_compat: curproxy->conf.args.ctx = ARGC_LOG; curproxy->conf.args.file = curproxy->conf.lfs_file; curproxy->conf.args.line = curproxy->conf.lfs_line; - parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY, - SMP_VAL_FE_LOG_END); + if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY, + SMP_VAL_FE_LOG_END)) { + cfgerr++; + } curproxy->conf.args.file = NULL; curproxy->conf.args.line = 0; } @@ -8282,9 +8287,12 @@ out_uri_auth_compat: curproxy->conf.args.ctx = ARGC_LOGSD; curproxy->conf.args.file = curproxy->conf.lfsd_file; curproxy->conf.args.line = curproxy->conf.lfsd_line; - parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY, - SMP_VAL_FE_LOG_END); - add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd); + if (!parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY, + SMP_VAL_FE_LOG_END)) { + cfgerr++; + } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd)) { + cfgerr++; + } curproxy->conf.args.file = NULL; curproxy->conf.args.line = 0; } @@ -8293,8 +8301,10 @@ out_uri_auth_compat: curproxy->conf.args.ctx = ARGC_UIF; curproxy->conf.args.file = curproxy->conf.uif_file; curproxy->conf.args.line = curproxy->conf.uif_line; - parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, - (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, + (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + cfgerr++; + } curproxy->conf.args.file = NULL; curproxy->conf.args.line = 0; } diff --git a/src/proto_http.c b/src/proto_http.c index 35169063d..725ea9c0a 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -9139,8 +9139,10 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li LIST_INIT(&rule->arg.hdr_add.fmt); proxy->conf.args.ctx = ARGC_HRQ; - parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); proxy->conf.lfs_line = proxy->conf.args.line; @@ -9169,8 +9171,10 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li } proxy->conf.args.ctx = ARGC_HRQ; - parse_logformat_string(args[cur_arg + 2], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(args[cur_arg + 2], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); @@ -9281,8 +9285,10 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li LIST_INIT(&rule->arg.map.key); proxy->conf.args.ctx = ARGC_HRQ; - parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); proxy->conf.lfs_line = proxy->conf.args.line; @@ -9307,8 +9313,10 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li LIST_INIT(&rule->arg.map.key); proxy->conf.args.ctx = ARGC_HRQ; - parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); proxy->conf.lfs_line = proxy->conf.args.line; @@ -9333,8 +9341,10 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li LIST_INIT(&rule->arg.map.key); proxy->conf.args.ctx = ARGC_HRQ; - parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); proxy->conf.lfs_line = proxy->conf.args.line; @@ -9362,12 +9372,16 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li proxy->conf.args.ctx = ARGC_HRQ; /* key pattern */ - parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + goto out_err; + } /* value pattern */ - parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.map.value, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.map.value, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); proxy->conf.lfs_line = proxy->conf.args.line; @@ -9537,8 +9551,10 @@ struct act_rule *parse_http_res_cond(const char **args, const char *file, int li LIST_INIT(&rule->arg.hdr_add.fmt); proxy->conf.args.ctx = ARGC_HRS; - parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR); + if (!parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); proxy->conf.lfs_line = proxy->conf.args.line; @@ -9567,8 +9583,10 @@ struct act_rule *parse_http_res_cond(const char **args, const char *file, int li } proxy->conf.args.ctx = ARGC_HRQ; - parse_logformat_string(args[cur_arg + 2], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR); + if (!parse_logformat_string(args[cur_arg + 2], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); @@ -9613,8 +9631,10 @@ struct act_rule *parse_http_res_cond(const char **args, const char *file, int li LIST_INIT(&rule->arg.map.key); proxy->conf.args.ctx = ARGC_HRS; - parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR); + if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); proxy->conf.lfs_line = proxy->conf.args.line; @@ -9640,8 +9660,10 @@ struct act_rule *parse_http_res_cond(const char **args, const char *file, int li LIST_INIT(&rule->arg.map.key); proxy->conf.args.ctx = ARGC_HRS; - parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR); + if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); proxy->conf.lfs_line = proxy->conf.args.line; @@ -9666,8 +9688,10 @@ struct act_rule *parse_http_res_cond(const char **args, const char *file, int li LIST_INIT(&rule->arg.map.key); proxy->conf.args.ctx = ARGC_HRS; - parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR); + if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); proxy->conf.lfs_line = proxy->conf.args.line; @@ -9696,12 +9720,16 @@ struct act_rule *parse_http_res_cond(const char **args, const char *file, int li proxy->conf.args.ctx = ARGC_HRS; /* key pattern */ - parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR); + if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.map.key, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR)) { + goto out_err; + } /* value pattern */ - parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.map.value, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR); + if (!parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.map.value, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR)) { + goto out_err; + } free(proxy->conf.lfs_file); proxy->conf.lfs_file = strdup(proxy->conf.args.file); @@ -9945,9 +9973,11 @@ struct redirect_rule *http_parse_redirect_rule(const char *file, int linenum, st */ curproxy->conf.args.ctx = ARGC_RDR; if (!(type == REDIRECT_TYPE_PREFIX && destination[0] == '/' && destination[1] == '\0')) { - parse_logformat_string(destination, curproxy, &rule->rdr_fmt, LOG_OPT_HTTP, - dir ? (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRS_HDR : SMP_VAL_BE_HRS_HDR - : (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(destination, curproxy, &rule->rdr_fmt, LOG_OPT_HTTP, + dir ? (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRS_HDR : SMP_VAL_BE_HRS_HDR + : (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + return NULL; + } free(curproxy->conf.lfs_file); curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); curproxy->conf.lfs_line = curproxy->conf.args.line; @@ -12440,8 +12470,10 @@ enum act_parse_ret parse_set_req_line(const char **args, int *orig_arg, struct p LIST_INIT(&rule->arg.http.logfmt); proxy->conf.args.ctx = ARGC_HRQ; - parse_logformat_string(args[cur_arg], proxy, &rule->arg.http.logfmt, LOG_OPT_HTTP, - (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); + if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.http.logfmt, LOG_OPT_HTTP, + (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR)) { + return ACT_RET_PRS_ERR; + } (*orig_arg)++; return ACT_RET_PRS_OK;