The `header_unique_id` member of `struct proxy` now is a `struct ist`. --- include/types/proxy.h | 2 +- src/cfgparse-listen.c | 23 +++++++++++++++++++---- src/http_ana.c | 5 ++--- 3 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/include/types/proxy.h b/include/types/proxy.h index f3b0e6bef..b64d448af 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 bd2275238..49c3c2df6 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 a97066085..2957aaec6 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -802,12 +802,11 @@ 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) { + if (isttest(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 (unlikely(!http_add_header(htx, sess->fe->header_unique_id, v))) goto return_int_err; } } -- 2.25.1