Don't expect NULL terminated name/value in nghttp2_hd_deflate_hd
If it is called through libnghttp2 internally, name/value pairs are all NULL-terminated. But it is one of public API, and we cannot expect that applications always make NULL-terminated string for name/value pairs.
This commit is contained in:
parent
c2eacc8b10
commit
2d5b42693d
|
@ -509,12 +509,14 @@ int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t flags, uint8_t *name,
|
||||||
flags = (uint8_t)(flags & ~NGHTTP2_HD_FLAG_NAME_ALLOC);
|
flags = (uint8_t)(flags & ~NGHTTP2_HD_FLAG_NAME_ALLOC);
|
||||||
ent->nv.name = (uint8_t *)"";
|
ent->nv.name = (uint8_t *)"";
|
||||||
} else {
|
} else {
|
||||||
/* copy including terminating NULL byte */
|
/* name may not be NULL terminated on compression. */
|
||||||
ent->nv.name = nghttp2_memdup(name, namelen + 1, mem);
|
ent->nv.name = nghttp2_mem_malloc(mem, namelen + 1);
|
||||||
if (ent->nv.name == NULL) {
|
if (ent->nv.name == NULL) {
|
||||||
rv = NGHTTP2_ERR_NOMEM;
|
rv = NGHTTP2_ERR_NOMEM;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
memcpy(ent->nv.name, name, namelen);
|
||||||
|
ent->nv.name[namelen] = '\0';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ent->nv.name = name;
|
ent->nv.name = name;
|
||||||
|
@ -525,12 +527,14 @@ int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t flags, uint8_t *name,
|
||||||
flags = (uint8_t)(flags & ~NGHTTP2_HD_FLAG_VALUE_ALLOC);
|
flags = (uint8_t)(flags & ~NGHTTP2_HD_FLAG_VALUE_ALLOC);
|
||||||
ent->nv.value = (uint8_t *)"";
|
ent->nv.value = (uint8_t *)"";
|
||||||
} else {
|
} else {
|
||||||
/* copy including terminating NULL byte */
|
/* value may not be NULL terminated on compression. */
|
||||||
ent->nv.value = nghttp2_memdup(value, valuelen + 1, mem);
|
ent->nv.value = nghttp2_mem_malloc(mem, valuelen + 1);
|
||||||
if (ent->nv.value == NULL) {
|
if (ent->nv.value == NULL) {
|
||||||
rv = NGHTTP2_ERR_NOMEM;
|
rv = NGHTTP2_ERR_NOMEM;
|
||||||
goto fail2;
|
goto fail2;
|
||||||
}
|
}
|
||||||
|
memcpy(ent->nv.value, value, valuelen);
|
||||||
|
ent->nv.value[valuelen] = '\0';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ent->nv.value = value;
|
ent->nv.value = value;
|
||||||
|
@ -1429,7 +1433,8 @@ static int deflate_nv(nghttp2_hd_deflater *deflater, nghttp2_bufs *bufs,
|
||||||
nghttp2_mem *mem;
|
nghttp2_mem *mem;
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
|
|
||||||
DEBUGF(fprintf(stderr, "deflatehd: deflating %s: %s\n", nv->name, nv->value));
|
DEBUGF(fprintf(stderr, "deflatehd: deflating %.*s: %.*s\n", (int)nv->namelen,
|
||||||
|
nv->name, (int)nv->valuelen, nv->value));
|
||||||
|
|
||||||
mem = deflater->ctx.mem;
|
mem = deflater->ctx.mem;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue