From: Christopher Faulet Date: Fri, 18 Nov 2022 14:46:06 +0000 (+0100) Subject: MINOR: cfgparse: Always check the section position X-Git-Tag: v2.7-dev9~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=037e3f87359dcf0e00c012748d5377690acfbdcc;p=thirdparty%2Fhaproxy.git MINOR: cfgparse: Always check the section position In diag mode, the section position is checked and a warning is emitted if a global section is defined after any non-global one. Now, this check is always performed. But the warning is still only emitted in diag mode. In addition, the result of this check is now stored in a global variable, to be used from anywhere. The aim of this patch is to be able to restrict usage of some global directives to the very first global sections. It will be useful to avoid undefined behaviors. Indeed, some config parts may depend on global settings and it is a problem if these settings are changed after. --- diff --git a/include/haproxy/cfgparse.h b/include/haproxy/cfgparse.h index 7c3d128bfb..b569b4dbc6 100644 --- a/include/haproxy/cfgparse.h +++ b/include/haproxy/cfgparse.h @@ -94,6 +94,7 @@ extern int cfg_maxconn; extern char *cfg_scope; extern struct cfg_kw_list cfg_keywords; extern char *cursection; +extern int non_global_section_parsed; int cfg_parse_global(const char *file, int linenum, char **args, int inv); int cfg_parse_listen(const char *file, int linenum, char **args, int inv); diff --git a/src/cfgparse.c b/src/cfgparse.c index a7652e9e35..998afcd5e6 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -104,6 +104,7 @@ char *cursection = NULL; int cfg_maxpconn = 0; /* # of simultaneous connections per proxy (-N) */ int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ char *cfg_scope = NULL; /* the current scope during the configuration parsing */ +int non_global_section_parsed = 0; /* how to handle default paths */ static enum default_path_mode { @@ -1577,16 +1578,14 @@ cfg_parse_track_sc_num(unsigned int *track_sc_num, * Detect a global section after a non-global one and output a diagnostic * warning. */ -static void check_section_position(char *section_name, - const char *file, int linenum, - int *non_global_parsed) +static void check_section_position(char *section_name, const char *file, int linenum) { if (strcmp(section_name, "global") == 0) { - if (*non_global_parsed == 1) + if ((global.mode & MODE_DIAG) && non_global_section_parsed == 1) _ha_diag_warning("parsing [%s:%d] : global section detected after a non-global one, the prevalence of their statements is unspecified\n", file, linenum); } - else if (*non_global_parsed == 0) { - *non_global_parsed = 1; + else if (non_global_section_parsed == 0) { + non_global_section_parsed = 1; } } @@ -1743,7 +1742,6 @@ int readcfgfile(const char *file) int missing_lf = -1; int nested_cond_lvl = 0; enum nested_cond_state nested_conds[MAXNESTEDCONDS]; - int non_global_section_parsed = 0; char *errmsg = NULL; global.cfg_curr_line = 0; @@ -2455,12 +2453,7 @@ next_line: cs = ics; free(global.cfg_curr_section); global.cfg_curr_section = strdup(*args[1] ? args[1] : args[0]); - - if (global.mode & MODE_DIAG) { - check_section_position(args[0], file, linenum, - &non_global_section_parsed); - } - + check_section_position(args[0], file, linenum); break; } }