From: Tim Duesterhus Date: Thu, 5 Mar 2020 16:56:35 +0000 (+0100) Subject: MINOR: proxy: Make `header_unique_id` a `struct ist` X-Git-Tag: v2.2-dev4~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0643b0e7e;p=thirdparty%2Fhaproxy.git MINOR: proxy: Make `header_unique_id` a `struct ist` The `header_unique_id` member of `struct proxy` now is a `struct ist`. --- diff --git a/include/types/proxy.h b/include/types/proxy.h index f3b0e6bef6..b64d448af7 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -405,7 +405,7 @@ struct proxy { struct list logformat; /* log_format linked list */ struct list logformat_sd; /* log_format linked list for the RFC5424 structured-data part */ struct buffer log_tag; /* override default syslog tag */ - char *header_unique_id; /* unique-id header */ + struct ist header_unique_id; /* unique-id header */ struct list format_unique_id; /* unique-id format */ int to_log; /* things to be logged (LW_*) */ int stop_time; /* date to stop listening, when stopping != 0 (int ticks) */ diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index bd22752387..5079800915 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -429,8 +429,15 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) } /* copy default header unique id */ - if (defproxy.header_unique_id) - curproxy->header_unique_id = strdup(defproxy.header_unique_id); + if (isttest(defproxy.header_unique_id)) { + const struct ist copy = istdup(defproxy.header_unique_id); + if (!isttest(copy)) { + ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } + curproxy->header_unique_id = copy; + } /* default compression options */ if (defproxy.comp != NULL) { @@ -3484,13 +3491,21 @@ stats_error_parsing: } else if (strcmp(args[0], "unique-id-header") == 0) { + char *copy; if (!*(args[1])) { ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); err_code |= ERR_ALERT | ERR_FATAL; goto out; } - free(curproxy->header_unique_id); - curproxy->header_unique_id = strdup(args[1]); + copy = strdup(args[1]); + if (copy == NULL) { + ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } + + istfree(&curproxy->header_unique_id); + curproxy->header_unique_id = ist(copy); } else if (strcmp(args[0], "log-format") == 0) { diff --git a/src/http_ana.c b/src/http_ana.c index a97066085f..010b170a34 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -802,14 +802,9 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit) } /* send unique ID if a "unique-id-header" is defined */ - if (sess->fe->header_unique_id) { - struct ist n, v; - n = ist2(sess->fe->header_unique_id, strlen(sess->fe->header_unique_id)); - v = ist2(s->unique_id, length); - - if (unlikely(!http_add_header(htx, n, v))) + if (isttest(sess->fe->header_unique_id) && + !http_add_header(htx, sess->fe->header_unique_id, ist2(s->unique_id, length))) goto return_int_err; - } } /*