]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: Use a trash chunk to store decoded string of the HTTP auth header
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 27 Jul 2017 13:18:52 +0000 (15:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 5 Sep 2017 08:36:28 +0000 (10:36 +0200)
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
src/haproxy.c
src/proto_http.c

index e07b550035337a83d110fb097cf45146dc7e0b5d..0fe779090e02ce49f052759424a5d2b00959fd7f 100644 (file)
@@ -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);
index 27d4417353ffddc95217224b65d75447f7eaeb10..488a076177d6db6e31d201b0c731e230102e74b0 100644 (file)
@@ -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) {
index 439e57fce0b0c987c2a5f9208436571af91d8904..ffa2f2a05a6302122da52e6a9506fe97e96db961 100644 (file)
@@ -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;