]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: hpack: make sure the hpack table can still be built standalone
authorWilly Tarreau <w@1wt.eu>
Fri, 22 May 2020 10:05:27 +0000 (12:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 22 May 2020 10:13:43 +0000 (12:13 +0200)
Recent commit 2bdcc70fa7 ("MEDIUM: hpack: use a pool for the hpack table")
made the hpack code finally use a pool with very unintrusive code that was
assumed to be trivial enough to adjust if the code needed to be reused
outside of haproxy. Unfortunately the code in contrib/hpack already uses
it and broke the oss-fuzz tests as it doesn't build anymore.

This patch adds an HPACK_STANDALONE macro to decide if we should use the
pools or malloc+free. The resulting macros are called hpack_alloc() and
hpack_free() respectively, and the size must be passed into the pool
itself.

include/common/hpack-tbl.h

index 44c0cc1178e6abfd77c5280d08ede637c9f68da0..6d529f20fc7ae95ecb8895eea74287b87f28c7c1 100644 (file)
@@ -136,6 +136,17 @@ enum {
 extern const struct http_hdr hpack_sht[HPACK_SHT_SIZE];
 extern struct pool_head *pool_head_hpack_tbl;
 
+/* when built outside of haproxy, HPACK_STANDALONE must be defined, and
+ * pool_head_hpack_tbl->size must be set to the DHT size.
+ */
+#ifndef HPACK_STANDALONE
+#define hpack_alloc(pool)      pool_alloc(pool)
+#define hpack_free(pool, ptr)  pool_free(pool, ptr)
+#else
+#define hpack_alloc(pool)      malloc(pool->size)
+#define hpack_free(pool, ptr)  free(ptr)
+#endif
+
 extern int __hpack_dht_make_room(struct hpack_dht *dht, unsigned int needed);
 extern int hpack_dht_insert(struct hpack_dht *dht, struct ist name, struct ist value);
 
@@ -243,7 +254,7 @@ static inline struct hpack_dht *hpack_dht_alloc()
        if (unlikely(!pool_head_hpack_tbl))
                return NULL;
 
-       dht = pool_alloc(pool_head_hpack_tbl);
+       dht = hpack_alloc(pool_head_hpack_tbl);
        if (dht)
                hpack_dht_init(dht, pool_head_hpack_tbl->size);
        return dht;
@@ -252,7 +263,7 @@ static inline struct hpack_dht *hpack_dht_alloc()
 /* free a dynamic headers table */
 static inline void hpack_dht_free(struct hpack_dht *dht)
 {
-       pool_free(pool_head_hpack_tbl, dht);
+       hpack_free(pool_head_hpack_tbl, dht);
 }
 
 #endif /* _COMMON_HPACK_TBL_H */