Commit aea4001d authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

deflatehd: Fix crash with -t option

parent eb0a894e
...@@ -258,18 +258,16 @@ static int perform(void) ...@@ -258,18 +258,16 @@ static int perform(void)
static int perform_from_http1text(void) static int perform_from_http1text(void)
{ {
char line[1 << 14]; char line[1 << 14];
std::vector<nghttp2_nv> nva;
int seq = 0; int seq = 0;
nghttp2_hd_deflater deflater; nghttp2_hd_deflater deflater;
init_deflater(&deflater); init_deflater(&deflater);
output_json_header(); output_json_header();
for(;;) { for(;;) {
size_t nvlen = 0; std::vector<nghttp2_nv> nva;
int end = 0; int end = 0;
size_t inputlen = 0; size_t inputlen = 0;
size_t i;
for(;;) { for(;;) {
nghttp2_nv *nv;
char *rv = fgets(line, sizeof(line), stdin); char *rv = fgets(line, sizeof(line), stdin);
char *val, *val_end; char *val, *val_end;
if(rv == nullptr) { if(rv == nullptr) {
...@@ -279,9 +277,9 @@ static int perform_from_http1text(void) ...@@ -279,9 +277,9 @@ static int perform_from_http1text(void)
break; break;
} }
nva.resize(nvlen); nva.emplace_back();
auto& nv = nva.back();
nv = &nva[nvlen];
val = strchr(line+1, ':'); val = strchr(line+1, ':');
if(val == nullptr) { if(val == nullptr) {
fprintf(stderr, "Bad HTTP/1 header field format at %d.\n", seq); fprintf(stderr, "Bad HTTP/1 header field format at %d.\n", seq);
...@@ -294,14 +292,13 @@ static int perform_from_http1text(void) ...@@ -294,14 +292,13 @@ static int perform_from_http1text(void)
++val_end); ++val_end);
*val_end = '\0'; *val_end = '\0';
nv->namelen = strlen(line); nv.namelen = strlen(line);
nv->valuelen = strlen(val); nv.valuelen = strlen(val);
nv->name = (uint8_t*)strdup(line); nv.name = (uint8_t*)strdup(line);
nv->value = (uint8_t*)strdup(val); nv.value = (uint8_t*)strdup(val);
nv->flags = NGHTTP2_NV_FLAG_NONE; nv.flags = NGHTTP2_NV_FLAG_NONE;
++nvlen; inputlen += nv.namelen + nv.valuelen;
inputlen += nv->namelen + nv->valuelen;
} }
if(!end) { if(!end) {
...@@ -311,10 +308,11 @@ static int perform_from_http1text(void) ...@@ -311,10 +308,11 @@ static int perform_from_http1text(void)
deflate_hd(&deflater, nva, inputlen, seq); deflate_hd(&deflater, nva, inputlen, seq);
} }
for(i = 0; i < nvlen; ++i) { for(auto& nv : nva) {
free(nva[i].name); free(nv.name);
free(nva[i].value); free(nv.value);
} }
if(end) break; if(end) break;
++seq; ++seq;
} }
......
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