Commit 595493a0 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Add debug output in nghttp2_hd

parent 9d630901
...@@ -26,9 +26,11 @@ ...@@ -26,9 +26,11 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include "nghttp2_frame.h" #include "nghttp2_frame.h"
#include "nghttp2_helper.h" #include "nghttp2_helper.h"
#include "nghttp2_int.h"
/* Make scalar initialization form of nghttp2_nv */ /* Make scalar initialization form of nghttp2_nv */
#define MAKE_NV(N, V) \ #define MAKE_NV(N, V) \
...@@ -463,6 +465,11 @@ static int emit_indexed_header(nghttp2_hd_context *context, ...@@ -463,6 +465,11 @@ static int emit_indexed_header(nghttp2_hd_context *context,
nghttp2_hd_entry *ent) nghttp2_hd_entry *ent)
{ {
int rv; int rv;
DEBUGF(fprintf(stderr, "Header emission:\n"));
DEBUGF(fwrite(ent->nv.name, ent->nv.namelen, 1, stderr));
DEBUGF(fprintf(stderr, ": "));
DEBUGF(fwrite(ent->nv.value, ent->nv.valuelen, 1, stderr));
DEBUGF(fprintf(stderr, "\n"));
/* ent->ref may be 0. This happens if the careless stupid encoder /* ent->ref may be 0. This happens if the careless stupid encoder
emits literal block larger than header table capacity with emits literal block larger than header table capacity with
indexing. */ indexing. */
...@@ -482,6 +489,11 @@ static int emit_newname_header(nghttp2_hd_context *context, ...@@ -482,6 +489,11 @@ static int emit_newname_header(nghttp2_hd_context *context,
uint8_t flags) uint8_t flags)
{ {
int rv; int rv;
DEBUGF(fprintf(stderr, "Header emission:\n"));
DEBUGF(fwrite(nv->name, nv->namelen, 1, stderr));
DEBUGF(fprintf(stderr, ": "));
DEBUGF(fwrite(nv->value, nv->valuelen, 1, stderr));
DEBUGF(fprintf(stderr, "\n"));
rv = add_nva(nva_out_ptr, rv = add_nva(nva_out_ptr,
nv->name, nv->namelen, nv->value, nv->valuelen); nv->name, nv->namelen, nv->value, nv->valuelen);
if(rv != 0) { if(rv != 0) {
...@@ -506,6 +518,11 @@ static int emit_indname_header(nghttp2_hd_context *context, ...@@ -506,6 +518,11 @@ static int emit_indname_header(nghttp2_hd_context *context,
uint8_t flags) uint8_t flags)
{ {
int rv; int rv;
DEBUGF(fprintf(stderr, "Header emission:\n"));
DEBUGF(fwrite(ent->nv.name, ent->nv.namelen, 1, stderr));
DEBUGF(fprintf(stderr, ": "));
DEBUGF(fwrite(value, valuelen, 1, stderr));
DEBUGF(fprintf(stderr, "\n"));
rv = add_emit_set(context, ent); rv = add_emit_set(context, ent);
if(rv != 0) { if(rv != 0) {
return rv; return rv;
...@@ -791,6 +808,11 @@ static nghttp2_hd_entry* add_hd_table_incremental(nghttp2_hd_context *context, ...@@ -791,6 +808,11 @@ static nghttp2_hd_entry* add_hd_table_incremental(nghttp2_hd_context *context,
} }
} }
} }
DEBUGF(fprintf(stderr, "Remove item from header table:\n"));
DEBUGF(fwrite(ent->nv.name, ent->nv.namelen, 1, stderr));
DEBUGF(fprintf(stderr, ": "));
DEBUGF(fwrite(ent->nv.value, ent->nv.valuelen, 1, stderr));
DEBUGF(fprintf(stderr, "\n"));
nghttp2_hd_ringbuf_pop_back(&context->hd_table); nghttp2_hd_ringbuf_pop_back(&context->hd_table);
if(--ent->ref == 0) { if(--ent->ref == 0) {
nghttp2_hd_entry_free(ent); nghttp2_hd_entry_free(ent);
...@@ -1225,6 +1247,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1225,6 +1247,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
int rv = 0; int rv = 0;
uint8_t *last = in + inlen; uint8_t *last = in + inlen;
nghttp2_nva_out nva_out; nghttp2_nva_out nva_out;
DEBUGF(fprintf(stderr, "infalte_hd start\n"));
memset(&nva_out, 0, sizeof(nva_out)); memset(&nva_out, 0, sizeof(nva_out));
if(inflater->bad) { if(inflater->bad) {
return NGHTTP2_ERR_HEADER_COMP; return NGHTTP2_ERR_HEADER_COMP;
...@@ -1237,16 +1260,20 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1237,16 +1260,20 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
ssize_t index; ssize_t index;
nghttp2_hd_entry *ent; nghttp2_hd_entry *ent;
in = decode_length(&index, in, last, 7); in = decode_length(&index, in, last, 7);
DEBUGF(fprintf(stderr, "Indexed repr index=%zd\n", index));
if(index < 0) { if(index < 0) {
DEBUGF(fprintf(stderr, "Index out of range index=%zd\n", index));
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
} }
if(index == 0) { if(index == 0) {
DEBUGF(fprintf(stderr, "Clearing reference set\n"));
clear_refset(inflater); clear_refset(inflater);
continue; continue;
} }
--index; --index;
if(!check_index_range(inflater, index)) { if(!check_index_range(inflater, index)) {
DEBUGF(fprintf(stderr, "Index out of range index=%zd\n", index));
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
} }
...@@ -1266,6 +1293,12 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1266,6 +1293,12 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
ent->flags ^= NGHTTP2_HD_FLAG_REFSET; ent->flags ^= NGHTTP2_HD_FLAG_REFSET;
if(ent->flags & NGHTTP2_HD_FLAG_REFSET) { if(ent->flags & NGHTTP2_HD_FLAG_REFSET) {
rv = emit_indexed_header(inflater, &nva_out, ent); rv = emit_indexed_header(inflater, &nva_out, ent);
} else {
DEBUGF(fprintf(stderr, "Toggle off item:\n"));
DEBUGF(fwrite(ent->nv.name, ent->nv.namelen, 1, stderr));
DEBUGF(fprintf(stderr, ": "));
DEBUGF(fwrite(ent->nv.value, ent->nv.valuelen, 1, stderr));
DEBUGF(fprintf(stderr, "\n"));
} }
} }
if(rv != 0) { if(rv != 0) {
...@@ -1277,6 +1310,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1277,6 +1310,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
ssize_t namelen, valuelen; ssize_t namelen, valuelen;
int name_huffman, value_huffman; int name_huffman, value_huffman;
uint8_t *decoded_huffman_name = NULL, *decoded_huffman_value = NULL; uint8_t *decoded_huffman_name = NULL, *decoded_huffman_value = NULL;
DEBUGF(fprintf(stderr, "Literal header repr - new name\n"));
if(++in == last) { if(++in == last) {
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
...@@ -1284,12 +1318,14 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1284,12 +1318,14 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
name_huffman = *in & (1 << 7); name_huffman = *in & (1 << 7);
in = decode_length(&namelen, in, last, 7); in = decode_length(&namelen, in, last, 7);
if(namelen < 0 || in + namelen > last) { if(namelen < 0 || in + namelen > last) {
DEBUGF(fprintf(stderr, "Invalid namelen=%zd\n", namelen));
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
} }
if(name_huffman) { if(name_huffman) {
rv = inflate_decode(&nv.name, in, namelen, inflater->side); rv = inflate_decode(&nv.name, in, namelen, inflater->side);
if(rv < 0) { if(rv < 0) {
DEBUGF(fprintf(stderr, "Name huffman decoding failed\n"));
goto fail; goto fail;
} }
decoded_huffman_name = nv.name; decoded_huffman_name = nv.name;
...@@ -1307,6 +1343,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1307,6 +1343,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
} }
if(in == last) { if(in == last) {
DEBUGF(fprintf(stderr, "No value found\n"));
free(decoded_huffman_name); free(decoded_huffman_name);
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
...@@ -1314,6 +1351,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1314,6 +1351,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
value_huffman = *in & (1 << 7); value_huffman = *in & (1 << 7);
in = decode_length(&valuelen, in, last, 7); in = decode_length(&valuelen, in, last, 7);
if(valuelen < 0 || in + valuelen > last) { if(valuelen < 0 || in + valuelen > last) {
DEBUGF(fprintf(stderr, "Invalid valuelen=%zd\n", valuelen));
free(decoded_huffman_name); free(decoded_huffman_name);
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
...@@ -1321,6 +1359,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1321,6 +1359,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
if(value_huffman) { if(value_huffman) {
rv = inflate_decode(&nv.value, in, valuelen, inflater->side); rv = inflate_decode(&nv.value, in, valuelen, inflater->side);
if(rv < 0) { if(rv < 0) {
DEBUGF(fprintf(stderr, "Value huffman decoding failed\n"));
free(decoded_huffman_name); free(decoded_huffman_name);
goto fail; goto fail;
} }
...@@ -1376,30 +1415,36 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1376,30 +1415,36 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
ssize_t valuelen, index; ssize_t valuelen, index;
int value_huffman; int value_huffman;
uint8_t *decoded_huffman_value = NULL; uint8_t *decoded_huffman_value = NULL;
DEBUGF(fprintf(stderr, "Literal header repr - indexed name\n"));
in = decode_length(&index, in, last, 6); in = decode_length(&index, in, last, 6);
if(index <= 0) { if(index <= 0) {
DEBUGF(fprintf(stderr, "Index out of range index=%zd\n", index));
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
} }
--index; --index;
if(!check_index_range(inflater, index)) { if(!check_index_range(inflater, index)) {
DEBUGF(fprintf(stderr, "Index out of range index=%zd\n", index));
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
} }
ent = nghttp2_hd_table_get(inflater, index); ent = nghttp2_hd_table_get(inflater, index);
if(in == last) { if(in == last) {
DEBUGF(fprintf(stderr, "No value found\n"));
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
} }
value_huffman = *in & (1 << 7); value_huffman = *in & (1 << 7);
in = decode_length(&valuelen, in , last, 7); in = decode_length(&valuelen, in , last, 7);
if(valuelen < 0 || in + valuelen > last) { if(valuelen < 0 || in + valuelen > last) {
DEBUGF(fprintf(stderr, "Invalid valuelen=%zd\n", valuelen));
rv = NGHTTP2_ERR_HEADER_COMP; rv = NGHTTP2_ERR_HEADER_COMP;
goto fail; goto fail;
} }
if(value_huffman) { if(value_huffman) {
rv = inflate_decode(&value, in, valuelen, inflater->side); rv = inflate_decode(&value, in, valuelen, inflater->side);
if(rv < 0) { if(rv < 0) {
DEBUGF(fprintf(stderr, "Value huffman decoding failed\n"));
goto fail; goto fail;
} }
decoded_huffman_value = value; decoded_huffman_value = value;
...@@ -1459,6 +1504,20 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater, ...@@ -1459,6 +1504,20 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
goto fail; goto fail;
} }
} }
#ifdef DEBUGBUILD
DEBUGF(fprintf(stderr, "Header table:\n"));
for(i = 0; i < inflater->hd_table.len; ++i) {
nghttp2_hd_entry *ent = nghttp2_hd_table_get(inflater, i);
DEBUGF(fprintf(stderr, "[%zu] (s=%zu) (%c) ",
i + 1,
entry_room(ent->nv.namelen, ent->nv.valuelen),
(ent->flags & NGHTTP2_HD_FLAG_REFSET) ? 'R' : ' '));
DEBUGF(fwrite(ent->nv.name, ent->nv.namelen, 1, stderr));
DEBUGF(fprintf(stderr, ": "));
DEBUGF(fwrite(ent->nv.value, ent->nv.valuelen, 1, stderr));
DEBUGF(fprintf(stderr, "\n"));
}
#endif /* DEBUGBUILD */
*nva_ptr = nva_out.nva; *nva_ptr = nva_out.nva;
return nva_out.nvlen; return nva_out.nvlen;
fail: fail:
......
...@@ -33,6 +33,12 @@ ...@@ -33,6 +33,12 @@
/* Macros, types and constants for internal use */ /* Macros, types and constants for internal use */
#ifdef DEBUGBUILD
#define DEBUGF(x) x
#else
#define DEBUGF(x) do { } while(0)
#endif
typedef int (*nghttp2_compar)(const void *lhs, const void *rhs); typedef int (*nghttp2_compar)(const void *lhs, const void *rhs);
/* Internal error code. They must be in the range [-499, -100], /* Internal error code. They must be in the range [-499, -100],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment