]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: chunk: add chunk_istcat() to concatenate an ist after a chunk
authorWilly Tarreau <w@1wt.eu>
Tue, 29 Oct 2019 12:02:15 +0000 (13:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 29 Oct 2019 12:09:14 +0000 (13:09 +0100)
We previously relied on chunk_cat(dst, b_fromist(src)) for this but it
is not reliable as the allocated buffer is inside the expression and
may be on a temporary stack. While it's possible to allocate stack space
for a struct and return a pointer to it, it's not possible to initialize
it form a temporary variable to prevent arguments from being evaluated
multiple times. Since this is only used to append an ist after a chunk,
let's instead have a chunk_istcat() function to perform exactly this
from a native ist.

The only call place (URI computation in the cache) was updated.

include/common/chunk.h
src/cache.c

index 18abca7bdd900b68718116eee0a2e069a8db0fc8..e44feea51647c169b9b59284e722b712ac5c8e1d 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <common/buf.h>
 #include <common/config.h>
+#include <common/ist.h>
 #include <common/memory.h>
 
 
@@ -117,6 +118,17 @@ static inline int chunk_cat(struct buffer *chk, const struct buffer *src)
        return 1;
 }
 
+/* appends ist <src> after <chk>. Returns 0 in case of failure. */
+static inline int chunk_istcat(struct buffer *chk, const struct ist src)
+{
+       if (unlikely(chk->data + src.len > chk->size))
+               return 0;
+
+       memcpy(chk->area + chk->data, src.ptr, src.len);
+       chk->data += src.len;
+       return 1;
+}
+
 /* copies memory area <src> into <chk> for <len> bytes. Returns 0 in
  * case of failure. No trailing zero is added.
  */
index 2ca745a94e60fab1dd7d28517e4e8111da290ec6..8e2acd1cb191ef5678efdd776e54df7112d76509 100644 (file)
@@ -1097,10 +1097,10 @@ int sha1_hosturi(struct stream *s)
         * well.
         */
        if (!(sl->flags & HTX_SL_F_HAS_AUTHORITY)) {
-               chunk_cat(trash, b_fromist(ist("https://")));
+               chunk_istcat(trash, ist("https://"));
                if (!http_find_header(htx, ist("Host"), &ctx, 0))
                        return 0;
-               chunk_cat(trash, b_fromist(ctx.value));
+               chunk_istcat(trash, ctx.value);
        }
 
        chunk_memcat(trash, uri.ptr, uri.len);