From 6988f678cd6c7c91c5ded5b13a4958b0d3f8ae9d Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 27 Jul 2017 15:18:52 +0200 Subject: [PATCH] MINOR: http: Use a trash chunk to store decoded string of the HTTP auth header This string is used in sample fetches so it is safe to use a preallocated trash chunk instead of a buffer dynamically allocated during HAProxy startup. --- include/proto/proto_http.h | 1 - src/haproxy.c | 2 -- src/proto_http.c | 14 +++++--------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h index e07b550035..0fe779090e 100644 --- a/include/proto/proto_http.h +++ b/include/proto/proto_http.h @@ -95,7 +95,6 @@ extern const int http_err_codes[HTTP_ERR_SIZE]; extern struct chunk http_err_chunks[HTTP_ERR_SIZE]; extern const char *HTTP_302; extern const char *HTTP_303; -extern char *get_http_auth_buff; int process_cli(struct stream *s); int process_srv_data(struct stream *s); diff --git a/src/haproxy.c b/src/haproxy.c index 27d4417353..488a076177 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1718,7 +1718,6 @@ static void init(int argc, char **argv) exit(1); } - get_http_auth_buff = calloc(1, global.tune.bufsize); fdinfo = calloc(1, sizeof(struct fdinfo) * (global.maxsock)); fdtab = calloc(1, sizeof(struct fdtab) * (global.maxsock)); @@ -2122,7 +2121,6 @@ void deinit(void) free(fdinfo); fdinfo = NULL; free(fdtab); fdtab = NULL; free(oldpids); oldpids = NULL; - free(get_http_auth_buff); get_http_auth_buff = NULL; free(global_listener_queue_task); global_listener_queue_task = NULL; list_for_each_entry_safe(log, logb, &global.logsrvs, list) { diff --git a/src/proto_http.c b/src/proto_http.c index 439e57fce0..ffa2f2a05a 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -1663,11 +1663,6 @@ const char *http_parse_reqline(struct http_msg *msg, * have the credentials overwritten by another stream in parallel. */ -/* This bufffer is initialized in the file 'src/haproxy.c'. This length is - * set according to global.tune.bufsize. - */ -char *get_http_auth_buff; - int get_http_auth(struct stream *s) { @@ -1713,22 +1708,23 @@ get_http_auth(struct stream *s) chunk_initlen(&txn->auth.method_data, p + 1, 0, ctx.vlen - len - 1); if (!strncasecmp("Basic", auth_method.str, auth_method.len)) { + struct chunk *http_auth = get_trash_chunk(); len = base64dec(txn->auth.method_data.str, txn->auth.method_data.len, - get_http_auth_buff, global.tune.bufsize - 1); + http_auth->str, global.tune.bufsize - 1); if (len < 0) return 0; - get_http_auth_buff[len] = '\0'; + http_auth->str[len] = '\0'; - p = strchr(get_http_auth_buff, ':'); + p = strchr(http_auth->str, ':'); if (!p) return 0; - txn->auth.user = get_http_auth_buff; + txn->auth.user = http_auth->str; *p = '\0'; txn->auth.pass = p+1;