Commit 73563de8 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Specify max length for header value and header block

The max length of header block is not used right now. It will
be used when header continuation is implemented.
parent 2b71598b
...@@ -794,7 +794,7 @@ ssize_t nghttp2_nv_array_from_cstr(nghttp2_nv **nva_ptr, const char **nv) ...@@ -794,7 +794,7 @@ ssize_t nghttp2_nv_array_from_cstr(nghttp2_nv **nva_ptr, const char **nv)
nghttp2_nv *p; nghttp2_nv *p;
for(i = 0; nv[i]; ++i) { for(i = 0; nv[i]; ++i) {
size_t len = strlen(nv[i]); size_t len = strlen(nv[i]);
if(len > (1 << 16) - 1) { if(len > NGHTTP2_MAX_HD_VALUE_LENGTH) {
return NGHTTP2_ERR_INVALID_ARGUMENT; return NGHTTP2_ERR_INVALID_ARGUMENT;
} }
buflen += len; buflen += len;
......
...@@ -33,8 +33,18 @@ ...@@ -33,8 +33,18 @@
#include "nghttp2_hd.h" #include "nghttp2_hd.h"
#include "nghttp2_buffer.h" #include "nghttp2_buffer.h"
/* The maximum payload length of a frame */
/* TODO The spec says the max payload length in HTTP is ((1 << 14) -
1) */
#define NGHTTP2_MAX_FRAME_SIZE ((1 << 16) - 1) #define NGHTTP2_MAX_FRAME_SIZE ((1 << 16) - 1)
/* The maximum header block length. This is not specified by the
spec. We just chose the arbitrary size */
#define NGHTTP2_MAX_HD_BLOCK_LENGTH ((1 << 16) - 1)
/* The maximum value length of name/value pair. This is not specified
by the spec. We just chose the arbitrary size */
#define NGHTTP2_MAX_HD_VALUE_LENGTH ((1 << 13) - 1)
#define NGHTTP2_STREAM_ID_MASK 0x7fffffff #define NGHTTP2_STREAM_ID_MASK 0x7fffffff
#define NGHTTP2_PRIORITY_MASK 0x7fffffff #define NGHTTP2_PRIORITY_MASK 0x7fffffff
#define NGHTTP2_WINDOW_SIZE_INCREMENT_MASK 0x7fffffff #define NGHTTP2_WINDOW_SIZE_INCREMENT_MASK 0x7fffffff
......
...@@ -168,13 +168,20 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void) ...@@ -168,13 +168,20 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void)
ssize_t framelen; ssize_t framelen;
nghttp2_nv *nva; nghttp2_nv *nva;
ssize_t nvlen; ssize_t nvlen;
size_t big_vallen = (1 << 16) - 1; size_t big_vallen = NGHTTP2_MAX_HD_VALUE_LENGTH;
char *big_val = malloc(big_vallen + 1); char *big_hds[17];
const char *big_hds[] = { "header", big_val, NULL }; size_t big_hdslen = sizeof(big_hds)/sizeof(big_hds[0]);
size_t i;
for(i = 0; i < big_hdslen; i += 2) {
big_hds[i] = (char*)"header";
big_hds[i+1] = malloc(big_vallen+1);
memset(big_hds[i+1], '0'+i, big_vallen);
big_hds[i+1][big_vallen] = '\0';
}
big_hds[big_hdslen - 1] = NULL;
memset(big_val, '0', big_vallen); nvlen = nghttp2_nv_array_from_cstr(&nva, (const char**)big_hds);
big_val[big_vallen] = '\0';
nvlen = nghttp2_nv_array_from_cstr(&nva, big_hds);
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_CLIENT); nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_CLIENT);
nghttp2_frame_headers_init(&frame, NGHTTP2_FLAG_END_STREAM, 1000000007, nghttp2_frame_headers_init(&frame, NGHTTP2_FLAG_END_STREAM, 1000000007,
0, nva, nvlen); 0, nva, nvlen);
...@@ -183,7 +190,9 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void) ...@@ -183,7 +190,9 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void)
nghttp2_frame_headers_free(&frame); nghttp2_frame_headers_free(&frame);
free(buf); free(buf);
free(big_val); for(i = 0; i < big_hdslen; i += 2) {
free(big_hds[i+1]);
}
nghttp2_hd_deflate_free(&deflater); nghttp2_hd_deflate_free(&deflater);
} }
......
...@@ -1278,22 +1278,27 @@ void test_nghttp2_session_send_headers_header_comp_error(void) ...@@ -1278,22 +1278,27 @@ void test_nghttp2_session_send_headers_header_comp_error(void)
{ {
nghttp2_session *session; nghttp2_session *session;
nghttp2_session_callbacks callbacks; nghttp2_session_callbacks callbacks;
const char *nv[] = { ":path", NULL, NULL };
size_t valuelen = 64*1024-1;
char *value = malloc(valuelen+1);
nghttp2_frame *frame = malloc(sizeof(nghttp2_frame)); nghttp2_frame *frame = malloc(sizeof(nghttp2_frame));
nghttp2_nv *nva; nghttp2_nv *nva;
ssize_t nvlen; ssize_t nvlen;
size_t vallen = NGHTTP2_MAX_HD_VALUE_LENGTH;
memset(value, '0', valuelen); char *nv[17];
value[valuelen] = '\0'; size_t nnv = sizeof(nv)/sizeof(nv[0]);
nv[1] = value; size_t i;
for(i = 0; i < nnv; i += 2) {
nv[i] = (char*)"header";
nv[i+1] = malloc(vallen+1);
memset(nv[i+1], '0'+i, vallen);
nv[i+1][vallen] = '\0';
}
nv[nnv - 1] = NULL;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.send_callback = null_send_callback; callbacks.send_callback = null_send_callback;
nghttp2_session_client_new(&session, &callbacks, NULL); nghttp2_session_client_new(&session, &callbacks, NULL);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nvlen = nghttp2_nv_array_from_cstr(&nva, (const char**)nv);
nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, -1, nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, -1,
NGHTTP2_PRI_DEFAULT, nva, nvlen); NGHTTP2_PRI_DEFAULT, nva, nvlen);
...@@ -1304,7 +1309,9 @@ void test_nghttp2_session_send_headers_header_comp_error(void) ...@@ -1304,7 +1309,9 @@ void test_nghttp2_session_send_headers_header_comp_error(void)
CU_ASSERT(session->goaway_flags & CU_ASSERT(session->goaway_flags &
(NGHTTP2_GOAWAY_SEND | NGHTTP2_GOAWAY_FAIL_ON_SEND)); (NGHTTP2_GOAWAY_SEND | NGHTTP2_GOAWAY_FAIL_ON_SEND));
free(value); for(i = 0; i < nnv; i += 2) {
free(nv[i+1]);
}
nghttp2_session_del(session); nghttp2_session_del(session);
} }
......
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