blob: 7c3605b684b6ebe4297d86409d1c55391d4436c0 [file] [log] [blame]
Willy Tarreau679790b2017-05-30 19:09:44 +02001/*
2 * HPACK decompressor (RFC7541)
3 *
4 * Copyright (C) 2014-2017 Willy Tarreau <willy@haproxy.org>
5 * Copyright (C) 2017 HAProxy Technologies
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#include <stdint.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32
Willy Tarreauc775f832017-12-30 13:17:37 +010033#include <common/standard.h>
Willy Tarreau679790b2017-05-30 19:09:44 +020034#include <common/hpack-dec.h>
35#include <common/hpack-huff.h>
36#include <common/hpack-tbl.h>
Willy Tarreau59a10fb2017-11-21 20:03:02 +010037#include <common/chunk.h>
Willy Tarreauc775f832017-12-30 13:17:37 +010038#include <common/h2.h>
Willy Tarreau679790b2017-05-30 19:09:44 +020039#include <common/ist.h>
40
41#include <types/global.h>
42
Willy Tarreau679790b2017-05-30 19:09:44 +020043
44#if defined(DEBUG_HPACK)
45#define hpack_debug_printf printf
Willy Tarreauc775f832017-12-30 13:17:37 +010046#define hpack_debug_hexdump debug_hexdump
Willy Tarreau679790b2017-05-30 19:09:44 +020047#else
48#define hpack_debug_printf(...) do { } while (0)
Willy Tarreauc775f832017-12-30 13:17:37 +010049#define hpack_debug_hexdump(...) do { } while (0)
Willy Tarreau679790b2017-05-30 19:09:44 +020050#endif
51
52/* reads a varint from <raw>'s lowest <b> bits and <len> bytes max (raw included).
53 * returns the 32-bit value on success after updating raw_in and len_in. Forces
54 * len_in to (uint32_t)-1 on truncated input.
55 */
56static uint32_t get_var_int(const uint8_t **raw_in, uint32_t *len_in, int b)
57{
58 uint32_t ret = 0;
59 int len = *len_in;
60 const uint8_t *raw = *raw_in;
61 uint8_t shift = 0;
62
63 len--;
64 ret = *(raw++) & ((1 << b) - 1);
65 if (ret != (uint32_t)((1 << b) - 1))
66 goto end;
67
68 while (1) {
69 if (!len)
70 goto too_short;
71 if (!(*raw & 128))
72 break;
73 ret += ((uint32_t)(*raw++) & 127) << shift;
74 shift += 7;
75 len--;
76 }
77
78 /* last 7 bits */
79 if (!len)
80 goto too_short;
81 len--;
82 ret += ((uint32_t)(*raw++) & 127) << shift;
83
84 end:
85 *raw_in = raw;
86 *len_in = len;
87 return ret;
88
89 too_short:
90 *len_in = (uint32_t)-1;
91 return 0;
92}
93
Willy Tarreau59a10fb2017-11-21 20:03:02 +010094/* returns the pseudo-header <idx> corresponds to among the following values :
95 * - 0 = unknown, the header's string needs to be used instead
96 * - 1 = ":authority"
97 * - 2 = ":method"
98 * - 3 = ":path"
99 * - 4 = ":scheme"
100 * - 5 = ":status"
Willy Tarreau679790b2017-05-30 19:09:44 +0200101 */
102static inline int hpack_idx_to_phdr(uint32_t idx)
103{
104 if (idx > 14)
105 return 0;
106
107 idx >>= 1;
108 idx <<= 2;
109 return (0x55554321U >> idx) & 0xF;
110}
111
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100112/* If <idx> designates a static header, returns <in>. Otherwise allocates some
113 * room from chunk <store> to duplicate <in> into it and returns the string
114 * allocated there. In case of allocation failure, returns a string whose
115 * pointer is NULL.
Willy Tarreau679790b2017-05-30 19:09:44 +0200116 */
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100117static inline struct ist hpack_alloc_string(struct chunk *store, int idx, struct ist in)
Willy Tarreau679790b2017-05-30 19:09:44 +0200118{
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100119 struct ist out;
Willy Tarreau679790b2017-05-30 19:09:44 +0200120
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100121 if (idx < HPACK_SHT_SIZE)
122 return in;
Willy Tarreau679790b2017-05-30 19:09:44 +0200123
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100124 out.len = in.len;
125 out.ptr = chunk_newstr(store);
126 if (unlikely(!out.ptr))
127 return out;
Willy Tarreau679790b2017-05-30 19:09:44 +0200128
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100129 if (unlikely(store->len + out.len > store->size)) {
130 out.ptr = NULL;
131 return out;
Willy Tarreau679790b2017-05-30 19:09:44 +0200132 }
133
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100134 store->len += out.len;
135 memcpy(out.ptr, in.ptr, out.len);
136 return out;
Willy Tarreau679790b2017-05-30 19:09:44 +0200137}
138
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100139/* decode an HPACK frame starting at <raw> for <len> bytes, using the dynamic
140 * headers table <dht>, produces the output into list <list> of <list_size>
141 * entries max, and uses pre-allocated buffer <tmp> for temporary storage (some
142 * list elements will point to it). Some <list> name entries may be made of a
143 * NULL pointer and a len, in which case they will designate a pseudo header
144 * index according to the values returned by hpack_idx_to_phdr() above. The
145 * number of <list> entries used is returned on success, or <0 on failure, with
146 * the opposite one of the HPACK_ERR_* codes. A last element is always zeroed
147 * and is not counted in the number of returned entries. This way the caller
148 * can use list[].n.len == 0 as a marker for the end of list.
Willy Tarreau679790b2017-05-30 19:09:44 +0200149 */
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100150int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len,
151 struct http_hdr *list, int list_size, struct chunk *tmp)
Willy Tarreau679790b2017-05-30 19:09:44 +0200152{
153 uint32_t idx;
154 uint32_t nlen;
155 uint32_t vlen;
156 uint8_t huff;
Willy Tarreau679790b2017-05-30 19:09:44 +0200157 struct ist name;
158 struct ist value;
Willy Tarreau679790b2017-05-30 19:09:44 +0200159 int must_index;
160 int ret;
Willy Tarreau679790b2017-05-30 19:09:44 +0200161
Willy Tarreauc775f832017-12-30 13:17:37 +0100162 hpack_debug_hexdump(stderr, "[HPACK-DEC] ", (const char *)raw, 0, len);
163
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100164 chunk_reset(tmp);
165 ret = 0;
Willy Tarreau679790b2017-05-30 19:09:44 +0200166 while (len) {
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100167 int __maybe_unused code = *raw; /* first byte, only for debugging */
Willy Tarreau679790b2017-05-30 19:09:44 +0200168
169 must_index = 0;
170 if (*raw >= 0x80) {
171 /* indexed header field */
172 if (*raw == 0x80) {
173 hpack_debug_printf("unhandled code 0x%02x (raw=%p, len=%d)\n", *raw, raw, len);
174 ret = -HPACK_ERR_UNKNOWN_OPCODE;
175 goto leave;
176 }
177
178 hpack_debug_printf("%02x: p14: indexed header field : ", code);
179
180 idx = get_var_int(&raw, &len, 7);
181 if (len == (uint32_t)-1) { // truncated
Willy Tarreauc775f832017-12-30 13:17:37 +0100182 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau679790b2017-05-30 19:09:44 +0200183 ret = -HPACK_ERR_TRUNCATED;
184 goto leave;
185 }
186
Willy Tarreauc775f832017-12-30 13:17:37 +0100187 hpack_debug_printf(" idx=%u ", idx);
188
Willy Tarreaud85ba4e2017-12-03 12:12:17 +0100189 if (!hpack_valid_idx(dht, idx)) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100190 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreaud85ba4e2017-12-03 12:12:17 +0100191 ret = -HPACK_ERR_TOO_LARGE;
192 goto leave;
193 }
194
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100195 value = hpack_alloc_string(tmp, idx, hpack_idx_to_value(dht, idx));
196 if (!value.ptr) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100197 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100198 ret = -HPACK_ERR_TOO_LARGE;
199 goto leave;
200 }
Willy Tarreau679790b2017-05-30 19:09:44 +0200201
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100202 /* here we don't index so we can always keep the pseudo header number */
203 name = ist2(NULL, hpack_idx_to_phdr(idx));
Willy Tarreau679790b2017-05-30 19:09:44 +0200204
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100205 if (!name.len) {
206 name = hpack_alloc_string(tmp, idx, hpack_idx_to_name(dht, idx));
207 if (!name.ptr) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100208 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100209 ret = -HPACK_ERR_TOO_LARGE;
210 goto leave;
211 }
212 }
213 /* <name> and <value> are now set and point to stable values */
Willy Tarreau679790b2017-05-30 19:09:44 +0200214 }
215 else if (*raw >= 0x20 && *raw <= 0x3f) {
216 /* max dyn table size change */
Willy Tarreauc775f832017-12-30 13:17:37 +0100217 hpack_debug_printf("%02x: p18: dynamic table size update : ", code);
218
Willy Tarreauc611e662017-12-03 18:09:21 +0100219 if (ret) {
220 /* 7541#4.2.1 : DHT size update must only be at the beginning */
Willy Tarreauc775f832017-12-30 13:17:37 +0100221 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreauc611e662017-12-03 18:09:21 +0100222 ret = -HPACK_ERR_TOO_LARGE;
223 goto leave;
224 }
225
Willy Tarreau679790b2017-05-30 19:09:44 +0200226 idx = get_var_int(&raw, &len, 5);
227 if (len == (uint32_t)-1) { // truncated
Willy Tarreauc775f832017-12-30 13:17:37 +0100228 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau679790b2017-05-30 19:09:44 +0200229 ret = -HPACK_ERR_TRUNCATED;
230 goto leave;
231 }
Willy Tarreauc775f832017-12-30 13:17:37 +0100232 hpack_debug_printf(" new len=%u\n", idx);
Willy Tarreau679790b2017-05-30 19:09:44 +0200233 continue;
234 }
235 else if (!(*raw & (*raw - 0x10))) {
236 /* 0x00, 0x10, and 0x40 (0x20 and 0x80 were already handled above) */
237
238 /* literal header field without/never/with incremental indexing -- literal name */
239 if (*raw == 0x00)
240 hpack_debug_printf("%02x: p17: literal without indexing : ", code);
241 else if (*raw == 0x10)
242 hpack_debug_printf("%02x: p18: literal never indexed : ", code);
243 else if (*raw == 0x40)
244 hpack_debug_printf("%02x: p16: literal with indexing : ", code);
245
246 if (*raw == 0x40)
247 must_index = 1;
248
249 raw++; len--;
250
251 /* retrieve name */
252 if (!len) { // truncated
Willy Tarreauc775f832017-12-30 13:17:37 +0100253 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau679790b2017-05-30 19:09:44 +0200254 ret = -HPACK_ERR_TRUNCATED;
255 goto leave;
256 }
257
258 huff = *raw & 0x80;
259 nlen = get_var_int(&raw, &len, 7);
260 if (len == (uint32_t)-1 || len < nlen) { // truncated
Willy Tarreauc775f832017-12-30 13:17:37 +0100261 hpack_debug_printf("##ERR@%d## (truncated): nlen=%d len=%d\n",
262 __LINE__, (int)nlen, (int)len);
Willy Tarreau679790b2017-05-30 19:09:44 +0200263 ret = -HPACK_ERR_TRUNCATED;
264 goto leave;
265 }
266
267 name = ist2(raw, nlen);
268
269 raw += nlen;
270 len -= nlen;
Willy Tarreau679790b2017-05-30 19:09:44 +0200271
272 if (huff) {
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100273 char *ntrash = chunk_newstr(tmp);
274 if (!ntrash) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100275 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100276 ret = -HPACK_ERR_TOO_LARGE;
277 goto leave;
278 }
279
280 nlen = huff_dec((const uint8_t *)name.ptr, name.len, ntrash, tmp->size - tmp->len);
Willy Tarreau679790b2017-05-30 19:09:44 +0200281 if (nlen == (uint32_t)-1) {
282 hpack_debug_printf("2: can't decode huffman.\n");
283 ret = -HPACK_ERR_HUFFMAN;
284 goto leave;
285 }
Willy Tarreauc775f832017-12-30 13:17:37 +0100286 hpack_debug_printf(" [name huff %d->%d] ", (int)name.len, (int)nlen);
287
Willy Tarreau679790b2017-05-30 19:09:44 +0200288 tmp->len += nlen; // make room for the value
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100289 name = ist2(ntrash, nlen);
Willy Tarreau679790b2017-05-30 19:09:44 +0200290 }
291
292 /* retrieve value */
293 if (!len) { // truncated
Willy Tarreauc775f832017-12-30 13:17:37 +0100294 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau679790b2017-05-30 19:09:44 +0200295 ret = -HPACK_ERR_TRUNCATED;
296 goto leave;
297 }
298
299 huff = *raw & 0x80;
300 vlen = get_var_int(&raw, &len, 7);
301 if (len == (uint32_t)-1 || len < vlen) { // truncated
Willy Tarreauc775f832017-12-30 13:17:37 +0100302 hpack_debug_printf("##ERR@%d## : vlen=%d len=%d\n",
303 __LINE__, (int)vlen, (int)len);
Willy Tarreau679790b2017-05-30 19:09:44 +0200304 ret = -HPACK_ERR_TRUNCATED;
305 goto leave;
306 }
307
308 value = ist2(raw, vlen);
309 raw += vlen;
310 len -= vlen;
311
312 if (huff) {
313 char *vtrash = chunk_newstr(tmp);
314 if (!vtrash) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100315 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100316 ret = -HPACK_ERR_TOO_LARGE;
Willy Tarreau679790b2017-05-30 19:09:44 +0200317 goto leave;
318 }
319
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100320 vlen = huff_dec((const uint8_t *)value.ptr, value.len, vtrash, tmp->size - tmp->len);
Willy Tarreau679790b2017-05-30 19:09:44 +0200321 if (vlen == (uint32_t)-1) {
322 hpack_debug_printf("3: can't decode huffman.\n");
323 ret = -HPACK_ERR_HUFFMAN;
324 goto leave;
325 }
Willy Tarreauc775f832017-12-30 13:17:37 +0100326 hpack_debug_printf(" [value huff %d->%d] ", (int)value.len, (int)vlen);
327
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100328 tmp->len += vlen; // make room for the value
Willy Tarreau679790b2017-05-30 19:09:44 +0200329 value = ist2(vtrash, vlen);
330 }
331
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100332 /* <name> and <value> are correctly filled here */
Willy Tarreau679790b2017-05-30 19:09:44 +0200333 }
334 else {
335 /* 0x01..0x0f : literal header field without indexing -- indexed name */
336 /* 0x11..0x1f : literal header field never indexed -- indexed name */
337 /* 0x41..0x7f : literal header field with incremental indexing -- indexed name */
338
339 if (*raw <= 0x0f)
340 hpack_debug_printf("%02x: p16: literal without indexing -- indexed name : ", code);
341 else if (*raw >= 0x41)
342 hpack_debug_printf("%02x: p15: literal with indexing -- indexed name : ", code);
343 else
344 hpack_debug_printf("%02x: p16: literal never indexed -- indexed name : ", code);
345
346 /* retrieve name index */
347 if (*raw >= 0x41) {
348 must_index = 1;
349 idx = get_var_int(&raw, &len, 6);
350 }
351 else
352 idx = get_var_int(&raw, &len, 4);
353
Willy Tarreauc775f832017-12-30 13:17:37 +0100354 hpack_debug_printf(" idx=%u ", idx);
355
Willy Tarreau679790b2017-05-30 19:09:44 +0200356 if (len == (uint32_t)-1 || !len) { // truncated
Willy Tarreauc775f832017-12-30 13:17:37 +0100357 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau679790b2017-05-30 19:09:44 +0200358 ret = -HPACK_ERR_TRUNCATED;
359 goto leave;
360 }
361
Willy Tarreaud85ba4e2017-12-03 12:12:17 +0100362 if (!hpack_valid_idx(dht, idx)) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100363 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreaud85ba4e2017-12-03 12:12:17 +0100364 ret = -HPACK_ERR_TOO_LARGE;
365 goto leave;
366 }
367
Willy Tarreau679790b2017-05-30 19:09:44 +0200368 /* retrieve value */
369 huff = *raw & 0x80;
370 vlen = get_var_int(&raw, &len, 7);
371 if (len == (uint32_t)-1 || len < vlen) { // truncated
Willy Tarreauc775f832017-12-30 13:17:37 +0100372 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau679790b2017-05-30 19:09:44 +0200373 ret = -HPACK_ERR_TRUNCATED;
374 goto leave;
375 }
376
377 value = ist2(raw, vlen);
378 raw += vlen;
379 len -= vlen;
380
381 if (huff) {
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100382 char *vtrash = chunk_newstr(tmp);
383 if (!vtrash) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100384 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100385 ret = -HPACK_ERR_TOO_LARGE;
386 goto leave;
387 }
388
389 vlen = huff_dec((const uint8_t *)value.ptr, value.len, vtrash, tmp->size - tmp->len);
Willy Tarreau679790b2017-05-30 19:09:44 +0200390 if (vlen == (uint32_t)-1) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100391 hpack_debug_printf("##ERR@%d## can't decode huffman : ilen=%d osize=%d\n",
392 __LINE__, (int)value.len, (int)(tmp->size - tmp->len));
393 hpack_debug_hexdump(stderr, "[HUFFMAN] ", value.ptr, 0, value.len);
Willy Tarreau679790b2017-05-30 19:09:44 +0200394 ret = -HPACK_ERR_HUFFMAN;
395 goto leave;
396 }
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100397 tmp->len += vlen; // make room for the value
398 value = ist2(vtrash, vlen);
Willy Tarreau679790b2017-05-30 19:09:44 +0200399 }
400
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100401 name = ist2(NULL, 0);
402 if (!must_index)
403 name.len = hpack_idx_to_phdr(idx);
Willy Tarreau679790b2017-05-30 19:09:44 +0200404
Willy Tarreaubb39b492017-12-30 16:56:28 +0100405 if (!name.len) {
406 name = hpack_alloc_string(tmp, idx, hpack_idx_to_name(dht, idx));
407 if (!name.ptr) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100408 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreaubb39b492017-12-30 16:56:28 +0100409 ret = -HPACK_ERR_TOO_LARGE;
410 goto leave;
411 }
412 }
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100413 /* <name> and <value> are correctly filled here */
Willy Tarreau679790b2017-05-30 19:09:44 +0200414 }
Willy Tarreau679790b2017-05-30 19:09:44 +0200415
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100416 /* here's what we have here :
417 * - name.len > 0
418 * - value is filled with either const data or data allocated from tmp
419 * - name.ptr == NULL && !must_index : known pseudo-header #name.len
420 * - name.ptr != NULL || must_index : general header, unknown pseudo-header or index needed
421 */
422 if (ret >= list_size) {
Willy Tarreauc775f832017-12-30 13:17:37 +0100423 hpack_debug_printf("##ERR@%d##\n", __LINE__);
Willy Tarreau679790b2017-05-30 19:09:44 +0200424 ret = -HPACK_ERR_TOO_LARGE;
425 goto leave;
426 }
427
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100428 list[ret].n = name;
429 list[ret].v = value;
430 ret++;
Willy Tarreau679790b2017-05-30 19:09:44 +0200431
432 if (must_index && hpack_dht_insert(dht, name, value) < 0) {
433 hpack_debug_printf("failed to find some room in the dynamic table\n");
434 ret = -HPACK_ERR_DHT_INSERT_FAIL;
435 goto leave;
436 }
437
Willy Tarreau679790b2017-05-30 19:09:44 +0200438 hpack_debug_printf("\e[1;34m%s\e[0m: ",
Willy Tarreauc775f832017-12-30 13:17:37 +0100439 name.ptr ? istpad(trash.str, name).ptr : h2_phdr_to_str(name.len));
Willy Tarreau679790b2017-05-30 19:09:44 +0200440
Willy Tarreauc775f832017-12-30 13:17:37 +0100441 hpack_debug_printf("\e[1;35m%s\e[0m [mustidx=%d, used=%d] [n=(%p,%d) v=(%p,%d)]\n",
442 istpad(trash.str, value).ptr, must_index, dht->used,
443 name.ptr, (int)name.len, value.ptr, (int)value.len);
Willy Tarreau679790b2017-05-30 19:09:44 +0200444 }
445
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100446 if (ret >= list_size) {
Willy Tarreau679790b2017-05-30 19:09:44 +0200447 ret = -HPACK_ERR_TOO_LARGE;
448 goto leave;
449 }
450
Willy Tarreau59a10fb2017-11-21 20:03:02 +0100451 /* put an end marker */
452 list[ret].n = list[ret].v = ist2(NULL, 0);
453 ret++;
Willy Tarreau679790b2017-05-30 19:09:44 +0200454
Willy Tarreau679790b2017-05-30 19:09:44 +0200455 leave:
Willy Tarreauc775f832017-12-30 13:17:37 +0100456 hpack_debug_printf("-- done: ret=%d list_size=%d --\n", (int)ret, (int)list_size);
Willy Tarreau679790b2017-05-30 19:09:44 +0200457 return ret;
458}