]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: log-format/conf: take into account the parse_logformat_string() return code
authorThierry FOURNIER / OZON.IO <thierry.fournier@ozon.io>
Tue, 22 Nov 2016 22:50:02 +0000 (23:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 17:54:26 +0000 (18:54 +0100)
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
src/proto_http.c

index e4bbfcc9e47ab534c770b6d225d4126b23465612..a355aa91cfa768177896718eeb61cc8fb11c4267 100644 (file)
@@ -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;
                }
index 35169063d9a25f3a59cec793a9d22d850116d3ad..725ea9c0a702e92d85394ef3171e43e927798418 100644 (file)
@@ -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;