memcpy(dst, src, len);
}
+/* Retruns 1 if the headers size with addition of <len> exceeds the maximum size
+ * allowed for headers.
+ */
+static inline __attribute__((always_inline)) int htx_hdrs_too_big(const struct htx *htx, int32_t len)
+{
+ return (sizeof(struct htx) + htx->hdrs_data + len > global.tune.bufsize);
+}
+
/* Defragments an HTX message. It removes unused blocks and unwraps the payloads
* part. A temporary buffer is used to do so. This function never fails. Most of
* time, we need keep a ref on a specific HTX block. Thus is <blk> is set, the
struct htx_blk *blk;
BUG_ON(blksz >= 256 << 20);
+ if (unlikely(type < HTX_BLK_EOH && htx_hdrs_too_big(htx, blksz)))
+ return NULL;
blk = htx_reserve_nxblk(htx, blksz);
if (!blk)
return NULL;
n = htx_get_blk_name(htx, blk);
v = htx_get_blk_value(htx, blk);
delta = new.len - old.len;
+
+ if (unlikely(htx_get_blk_type(blk) < HTX_BLK_EOH && htx_hdrs_too_big(htx, delta)))
+ return NULL;
+
ret = htx_prepare_blk_expansion(htx, blk, delta);
if (!ret)
return NULL; /* not enough space */
return NULL;
delta = name.len + value.len - htx_get_blksz(blk);
+ if (unlikely(htx_hdrs_too_big(htx, delta)))
+ return NULL;
+
ret = htx_prepare_blk_expansion(htx, blk, delta);
if (!ret)
return NULL; /* not enough space */
sz = htx_get_blksz(blk);
delta = sizeof(*sl) + p1.len + p2.len + p3.len - sz;
+
+ if (unlikely(htx_hdrs_too_big(htx, delta)))
+ return NULL;
+
ret = htx_prepare_blk_expansion(htx, blk, delta);
if (!ret)
return NULL; /* not enough space */