Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2960ef1

Browse files
gengjiawentargos
authored andcommittedDec 1, 2019
deps: update nghttp2 to 1.40.0
PR-URL: #30493 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 2ad7003 commit 2960ef1

11 files changed

+4387
-4432
lines changed
 

‎deps/nghttp2/lib/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if(HAVE_CUNIT OR ENABLE_STATIC_LIB)
6262
set_target_properties(nghttp2_static PROPERTIES
6363
COMPILE_FLAGS "${WARNCFLAGS}"
6464
VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}
65-
ARCHIVE_OUTPUT_NAME nghttp2
65+
ARCHIVE_OUTPUT_NAME nghttp2_static
6666
)
6767
target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB")
6868
if(ENABLE_STATIC_LIB)

‎deps/nghttp2/lib/includes/nghttp2/nghttp2.h

+13
Original file line numberDiff line numberDiff line change
@@ -4769,6 +4769,19 @@ NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len);
47694769
*/
47704770
NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len);
47714771

4772+
/**
4773+
* @function
4774+
*
4775+
* Returns nonzero if the |value| which is supposed to the value of
4776+
* :authority or host header field is valid according to
4777+
* https://tools.ietf.org/html/rfc3986#section-3.2
4778+
*
4779+
* |value| is valid if it merely consists of the allowed characters.
4780+
* In particular, it does not check whether |value| follows the syntax
4781+
* of authority.
4782+
*/
4783+
NGHTTP2_EXTERN int nghttp2_check_authority(const uint8_t *value, size_t len);
4784+
47724785
/* HPACK API */
47734786

47744787
struct nghttp2_hd_deflater;

‎deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
* @macro
3030
* Version number of the nghttp2 library release
3131
*/
32-
#define NGHTTP2_VERSION "1.39.2"
32+
#define NGHTTP2_VERSION "1.40.0"
3333

3434
/**
3535
* @macro
3636
* Numerical representation of the version number of the nghttp2 library
3737
* release. This is a 24 bit number with 8 bits for major number, 8 bits
3838
* for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
3939
*/
40-
#define NGHTTP2_VERSION_NUM 0x012702
40+
#define NGHTTP2_VERSION_NUM 0x012800
4141

4242
#endif /* NGHTTP2VER_H */

‎deps/nghttp2/lib/nghttp2_hd.c

+5
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,11 @@ static ssize_t hd_inflate_read_huff(nghttp2_hd_inflater *inflater,
16941694
DEBUGF("inflatehd: huffman decoding failed\n");
16951695
return readlen;
16961696
}
1697+
if (nghttp2_hd_huff_decode_failure_state(&inflater->huff_decode_ctx)) {
1698+
DEBUGF("inflatehd: huffman decoding failed\n");
1699+
return NGHTTP2_ERR_HEADER_COMP;
1700+
}
1701+
16971702
inflater->left -= (size_t)readlen;
16981703
return readlen;
16991704
}

‎deps/nghttp2/lib/nghttp2_hd.h

+6
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,10 @@ ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx,
430430
nghttp2_buf *buf, const uint8_t *src,
431431
size_t srclen, int fin);
432432

433+
/*
434+
* nghttp2_hd_huff_decode_failure_state returns nonzero if |ctx|
435+
* indicates that huffman decoding context is in failure state.
436+
*/
437+
int nghttp2_hd_huff_decode_failure_state(nghttp2_hd_huff_decode_context *ctx);
438+
433439
#endif /* NGHTTP2_HD_H */

‎deps/nghttp2/lib/nghttp2_hd_huffman.c

+68-155
Original file line numberDiff line numberDiff line change
@@ -29,114 +29,7 @@
2929
#include <stdio.h>
3030

3131
#include "nghttp2_hd.h"
32-
33-
/*
34-
* Encodes huffman code |sym| into |*dest_ptr|, whose least |rembits|
35-
* bits are not filled yet. The |rembits| must be in range [1, 8],
36-
* inclusive. At the end of the process, the |*dest_ptr| is updated
37-
* and points where next output should be placed. The number of
38-
* unfilled bits in the pointed location is returned.
39-
*/
40-
static ssize_t huff_encode_sym(nghttp2_bufs *bufs, size_t *avail_ptr,
41-
size_t rembits, const nghttp2_huff_sym *sym) {
42-
int rv;
43-
size_t nbits = sym->nbits;
44-
uint32_t code = sym->code;
45-
46-
/* We assume that sym->nbits <= 32 */
47-
if (rembits > nbits) {
48-
nghttp2_bufs_fast_orb_hold(bufs, (uint8_t)(code << (rembits - nbits)));
49-
return (ssize_t)(rembits - nbits);
50-
}
51-
52-
if (rembits == nbits) {
53-
nghttp2_bufs_fast_orb(bufs, (uint8_t)code);
54-
--*avail_ptr;
55-
return 8;
56-
}
57-
58-
nghttp2_bufs_fast_orb(bufs, (uint8_t)(code >> (nbits - rembits)));
59-
--*avail_ptr;
60-
61-
nbits -= rembits;
62-
if (nbits & 0x7) {
63-
/* align code to MSB byte boundary */
64-
code <<= 8 - (nbits & 0x7);
65-
}
66-
67-
if (*avail_ptr < (nbits + 7) / 8) {
68-
/* slow path */
69-
if (nbits > 24) {
70-
rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 24));
71-
if (rv != 0) {
72-
return rv;
73-
}
74-
nbits -= 8;
75-
}
76-
if (nbits > 16) {
77-
rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 16));
78-
if (rv != 0) {
79-
return rv;
80-
}
81-
nbits -= 8;
82-
}
83-
if (nbits > 8) {
84-
rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 8));
85-
if (rv != 0) {
86-
return rv;
87-
}
88-
nbits -= 8;
89-
}
90-
if (nbits == 8) {
91-
rv = nghttp2_bufs_addb(bufs, (uint8_t)code);
92-
if (rv != 0) {
93-
return rv;
94-
}
95-
*avail_ptr = nghttp2_bufs_cur_avail(bufs);
96-
return 8;
97-
}
98-
99-
rv = nghttp2_bufs_addb_hold(bufs, (uint8_t)code);
100-
if (rv != 0) {
101-
return rv;
102-
}
103-
*avail_ptr = nghttp2_bufs_cur_avail(bufs);
104-
return (ssize_t)(8 - nbits);
105-
}
106-
107-
/* fast path, since most code is less than 8 */
108-
if (nbits < 8) {
109-
nghttp2_bufs_fast_addb_hold(bufs, (uint8_t)code);
110-
*avail_ptr = nghttp2_bufs_cur_avail(bufs);
111-
return (ssize_t)(8 - nbits);
112-
}
113-
114-
/* handle longer code path */
115-
if (nbits > 24) {
116-
nghttp2_bufs_fast_addb(bufs, (uint8_t)(code >> 24));
117-
nbits -= 8;
118-
}
119-
120-
if (nbits > 16) {
121-
nghttp2_bufs_fast_addb(bufs, (uint8_t)(code >> 16));
122-
nbits -= 8;
123-
}
124-
125-
if (nbits > 8) {
126-
nghttp2_bufs_fast_addb(bufs, (uint8_t)(code >> 8));
127-
nbits -= 8;
128-
}
129-
130-
if (nbits == 8) {
131-
nghttp2_bufs_fast_addb(bufs, (uint8_t)code);
132-
*avail_ptr = nghttp2_bufs_cur_avail(bufs);
133-
return 8;
134-
}
135-
136-
nghttp2_bufs_fast_addb_hold(bufs, (uint8_t)code);
137-
*avail_ptr = nghttp2_bufs_cur_avail(bufs);
138-
return (ssize_t)(8 - nbits);
139-
}
32+
#include "nghttp2_net.h"
14033

14134
size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len) {
14235
size_t i;
@@ -151,81 +44,101 @@ size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len) {
15144

15245
int nghttp2_hd_huff_encode(nghttp2_bufs *bufs, const uint8_t *src,
15346
size_t srclen) {
154-
int rv;
155-
ssize_t rembits = 8;
156-
size_t i;
47+
const nghttp2_huff_sym *sym;
48+
const uint8_t *end = src + srclen;
49+
uint64_t code = 0;
50+
uint32_t x;
51+
size_t nbits = 0;
15752
size_t avail;
53+
int rv;
15854

15955
avail = nghttp2_bufs_cur_avail(bufs);
16056

161-
for (i = 0; i < srclen; ++i) {
162-
const nghttp2_huff_sym *sym = &huff_sym_table[src[i]];
163-
if (rembits == 8) {
164-
if (avail) {
165-
nghttp2_bufs_fast_addb_hold(bufs, 0);
166-
} else {
167-
rv = nghttp2_bufs_addb_hold(bufs, 0);
168-
if (rv != 0) {
169-
return rv;
170-
}
171-
avail = nghttp2_bufs_cur_avail(bufs);
57+
for (; src != end;) {
58+
sym = &huff_sym_table[*src++];
59+
code |= (uint64_t)sym->code << (32 - nbits);
60+
nbits += sym->nbits;
61+
if (nbits < 32) {
62+
continue;
63+
}
64+
if (avail >= 4) {
65+
x = htonl((uint32_t)(code >> 32));
66+
memcpy(bufs->cur->buf.last, &x, 4);
67+
bufs->cur->buf.last += 4;
68+
avail -= 4;
69+
code <<= 32;
70+
nbits -= 32;
71+
continue;
72+
}
73+
74+
for (; nbits >= 8;) {
75+
rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 56));
76+
if (rv != 0) {
77+
return rv;
17278
}
79+
code <<= 8;
80+
nbits -= 8;
17381
}
174-
rembits = huff_encode_sym(bufs, &avail, (size_t)rembits, sym);
175-
if (rembits < 0) {
176-
return (int)rembits;
82+
83+
avail = nghttp2_bufs_cur_avail(bufs);
84+
}
85+
86+
for (; nbits >= 8;) {
87+
rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 56));
88+
if (rv != 0) {
89+
return rv;
17790
}
91+
code <<= 8;
92+
nbits -= 8;
17893
}
179-
/* 256 is special terminal symbol, pad with its prefix */
180-
if (rembits < 8) {
181-
/* if rembits < 8, we should have at least 1 buffer space
182-
available */
183-
const nghttp2_huff_sym *sym = &huff_sym_table[256];
184-
assert(avail);
185-
/* Caution we no longer adjust avail here */
186-
nghttp2_bufs_fast_orb(
187-
bufs, (uint8_t)(sym->code >> (sym->nbits - (size_t)rembits)));
94+
95+
if (nbits) {
96+
rv = nghttp2_bufs_addb(
97+
bufs, (uint8_t)((uint8_t)(code >> 56) | ((1 << (8 - nbits)) - 1)));
98+
if (rv != 0) {
99+
return rv;
100+
}
188101
}
189102

190103
return 0;
191104
}
192105

193106
void nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx) {
194-
ctx->state = 0;
195-
ctx->accept = 1;
107+
ctx->fstate = NGHTTP2_HUFF_ACCEPTED;
196108
}
197109

198110
ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx,
199111
nghttp2_buf *buf, const uint8_t *src,
200112
size_t srclen, int final) {
201-
size_t i;
113+
const uint8_t *end = src + srclen;
114+
nghttp2_huff_decode node = {ctx->fstate, 0};
115+
const nghttp2_huff_decode *t = &node;
116+
uint8_t c;
202117

203118
/* We use the decoding algorithm described in
204119
http://graphics.ics.uci.edu/pub/Prefix.pdf */
205-
for (i = 0; i < srclen; ++i) {
206-
const nghttp2_huff_decode *t;
207-
208-
t = &huff_decode_table[ctx->state][src[i] >> 4];
209-
if (t->flags & NGHTTP2_HUFF_FAIL) {
210-
return NGHTTP2_ERR_HEADER_COMP;
211-
}
212-
if (t->flags & NGHTTP2_HUFF_SYM) {
120+
for (; src != end;) {
121+
c = *src++;
122+
t = &huff_decode_table[t->fstate & 0x1ff][c >> 4];
123+
if (t->fstate & NGHTTP2_HUFF_SYM) {
213124
*buf->last++ = t->sym;
214125
}
215126

216-
t = &huff_decode_table[t->state][src[i] & 0xf];
217-
if (t->flags & NGHTTP2_HUFF_FAIL) {
218-
return NGHTTP2_ERR_HEADER_COMP;
219-
}
220-
if (t->flags & NGHTTP2_HUFF_SYM) {
127+
t = &huff_decode_table[t->fstate & 0x1ff][c & 0xf];
128+
if (t->fstate & NGHTTP2_HUFF_SYM) {
221129
*buf->last++ = t->sym;
222130
}
223-
224-
ctx->state = t->state;
225-
ctx->accept = (t->flags & NGHTTP2_HUFF_ACCEPTED) != 0;
226131
}
227-
if (final && !ctx->accept) {
132+
133+
ctx->fstate = t->fstate;
134+
135+
if (final && !(ctx->fstate & NGHTTP2_HUFF_ACCEPTED)) {
228136
return NGHTTP2_ERR_HEADER_COMP;
229137
}
230-
return (ssize_t)i;
138+
139+
return (ssize_t)srclen;
140+
}
141+
142+
int nghttp2_hd_huff_decode_failure_state(nghttp2_hd_huff_decode_context *ctx) {
143+
return ctx->fstate == 0x100;
231144
}

‎deps/nghttp2/lib/nghttp2_hd_huffman.h

+12-17
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,29 @@
3434
typedef enum {
3535
/* FSA accepts this state as the end of huffman encoding
3636
sequence. */
37-
NGHTTP2_HUFF_ACCEPTED = 1,
37+
NGHTTP2_HUFF_ACCEPTED = 1 << 14,
3838
/* This state emits symbol */
39-
NGHTTP2_HUFF_SYM = (1 << 1),
40-
/* If state machine reaches this state, decoding fails. */
41-
NGHTTP2_HUFF_FAIL = (1 << 2)
39+
NGHTTP2_HUFF_SYM = 1 << 15,
4240
} nghttp2_huff_decode_flag;
4341

4442
typedef struct {
45-
/* huffman decoding state, which is actually the node ID of internal
46-
huffman tree. We have 257 leaf nodes, but they are identical to
47-
root node other than emitting a symbol, so we have 256 internal
48-
nodes [1..255], inclusive. */
49-
uint8_t state;
50-
/* bitwise OR of zero or more of the nghttp2_huff_decode_flag */
51-
uint8_t flags;
43+
/* fstate is the current huffman decoding state, which is actually
44+
the node ID of internal huffman tree with
45+
nghttp2_huff_decode_flag OR-ed. We have 257 leaf nodes, but they
46+
are identical to root node other than emitting a symbol, so we
47+
have 256 internal nodes [1..255], inclusive. The node ID 256 is
48+
a special node and it is a terminal state that means decoding
49+
failed. */
50+
uint16_t fstate;
5251
/* symbol if NGHTTP2_HUFF_SYM flag set */
5352
uint8_t sym;
5453
} nghttp2_huff_decode;
5554

5655
typedef nghttp2_huff_decode huff_decode_table_type[16];
5756

5857
typedef struct {
59-
/* Current huffman decoding state. We stripped leaf nodes, so the
60-
value range is [0..255], inclusive. */
61-
uint8_t state;
62-
/* nonzero if we can say that the decoding process succeeds at this
63-
state */
64-
uint8_t accept;
58+
/* fstate is the current huffman decoding state. */
59+
uint16_t fstate;
6560
} nghttp2_hd_huff_decode_context;
6661

6762
typedef struct {

‎deps/nghttp2/lib/nghttp2_hd_huffman_data.c

+4,180-4,161
Large diffs are not rendered by default.

‎deps/nghttp2/lib/nghttp2_helper.c

+78
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,84 @@ int nghttp2_check_header_value(const uint8_t *value, size_t len) {
505505
return 1;
506506
}
507507

508+
/* Generated by genauthroitychartbl.py */
509+
static char VALID_AUTHORITY_CHARS[] = {
510+
0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */,
511+
0 /* EOT */, 0 /* ENQ */, 0 /* ACK */, 0 /* BEL */,
512+
0 /* BS */, 0 /* HT */, 0 /* LF */, 0 /* VT */,
513+
0 /* FF */, 0 /* CR */, 0 /* SO */, 0 /* SI */,
514+
0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */,
515+
0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */,
516+
0 /* CAN */, 0 /* EM */, 0 /* SUB */, 0 /* ESC */,
517+
0 /* FS */, 0 /* GS */, 0 /* RS */, 0 /* US */,
518+
0 /* SPC */, 1 /* ! */, 0 /* " */, 0 /* # */,
519+
1 /* $ */, 1 /* % */, 1 /* & */, 1 /* ' */,
520+
1 /* ( */, 1 /* ) */, 1 /* * */, 1 /* + */,
521+
1 /* , */, 1 /* - */, 1 /* . */, 0 /* / */,
522+
1 /* 0 */, 1 /* 1 */, 1 /* 2 */, 1 /* 3 */,
523+
1 /* 4 */, 1 /* 5 */, 1 /* 6 */, 1 /* 7 */,
524+
1 /* 8 */, 1 /* 9 */, 1 /* : */, 1 /* ; */,
525+
0 /* < */, 1 /* = */, 0 /* > */, 0 /* ? */,
526+
1 /* @ */, 1 /* A */, 1 /* B */, 1 /* C */,
527+
1 /* D */, 1 /* E */, 1 /* F */, 1 /* G */,
528+
1 /* H */, 1 /* I */, 1 /* J */, 1 /* K */,
529+
1 /* L */, 1 /* M */, 1 /* N */, 1 /* O */,
530+
1 /* P */, 1 /* Q */, 1 /* R */, 1 /* S */,
531+
1 /* T */, 1 /* U */, 1 /* V */, 1 /* W */,
532+
1 /* X */, 1 /* Y */, 1 /* Z */, 1 /* [ */,
533+
0 /* \ */, 1 /* ] */, 0 /* ^ */, 1 /* _ */,
534+
0 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */,
535+
1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */,
536+
1 /* h */, 1 /* i */, 1 /* j */, 1 /* k */,
537+
1 /* l */, 1 /* m */, 1 /* n */, 1 /* o */,
538+
1 /* p */, 1 /* q */, 1 /* r */, 1 /* s */,
539+
1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */,
540+
1 /* x */, 1 /* y */, 1 /* z */, 0 /* { */,
541+
0 /* | */, 0 /* } */, 1 /* ~ */, 0 /* DEL */,
542+
0 /* 0x80 */, 0 /* 0x81 */, 0 /* 0x82 */, 0 /* 0x83 */,
543+
0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */, 0 /* 0x87 */,
544+
0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
545+
0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */,
546+
0 /* 0x90 */, 0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */,
547+
0 /* 0x94 */, 0 /* 0x95 */, 0 /* 0x96 */, 0 /* 0x97 */,
548+
0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */, 0 /* 0x9b */,
549+
0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
550+
0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */,
551+
0 /* 0xa4 */, 0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */,
552+
0 /* 0xa8 */, 0 /* 0xa9 */, 0 /* 0xaa */, 0 /* 0xab */,
553+
0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */, 0 /* 0xaf */,
554+
0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
555+
0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */,
556+
0 /* 0xb8 */, 0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */,
557+
0 /* 0xbc */, 0 /* 0xbd */, 0 /* 0xbe */, 0 /* 0xbf */,
558+
0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */, 0 /* 0xc3 */,
559+
0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
560+
0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */,
561+
0 /* 0xcc */, 0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */,
562+
0 /* 0xd0 */, 0 /* 0xd1 */, 0 /* 0xd2 */, 0 /* 0xd3 */,
563+
0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */, 0 /* 0xd7 */,
564+
0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
565+
0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */,
566+
0 /* 0xe0 */, 0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */,
567+
0 /* 0xe4 */, 0 /* 0xe5 */, 0 /* 0xe6 */, 0 /* 0xe7 */,
568+
0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */, 0 /* 0xeb */,
569+
0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
570+
0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */,
571+
0 /* 0xf4 */, 0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */,
572+
0 /* 0xf8 */, 0 /* 0xf9 */, 0 /* 0xfa */, 0 /* 0xfb */,
573+
0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */, 0 /* 0xff */
574+
};
575+
576+
int nghttp2_check_authority(const uint8_t *value, size_t len) {
577+
const uint8_t *last;
578+
for (last = value + len; value != last; ++value) {
579+
if (!VALID_AUTHORITY_CHARS[*value]) {
580+
return 0;
581+
}
582+
}
583+
return 1;
584+
}
585+
508586
uint8_t *nghttp2_cpymem(uint8_t *dest, const void *src, size_t len) {
509587
if (len == 0) {
510588
return dest;

‎deps/nghttp2/lib/nghttp2_http.c

+1-79
Original file line numberDiff line numberDiff line change
@@ -305,84 +305,6 @@ static int http_response_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
305305
return 0;
306306
}
307307

308-
/* Generated by genauthroitychartbl.py */
309-
static char VALID_AUTHORITY_CHARS[] = {
310-
0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */,
311-
0 /* EOT */, 0 /* ENQ */, 0 /* ACK */, 0 /* BEL */,
312-
0 /* BS */, 0 /* HT */, 0 /* LF */, 0 /* VT */,
313-
0 /* FF */, 0 /* CR */, 0 /* SO */, 0 /* SI */,
314-
0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */,
315-
0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */,
316-
0 /* CAN */, 0 /* EM */, 0 /* SUB */, 0 /* ESC */,
317-
0 /* FS */, 0 /* GS */, 0 /* RS */, 0 /* US */,
318-
0 /* SPC */, 1 /* ! */, 0 /* " */, 0 /* # */,
319-
1 /* $ */, 1 /* % */, 1 /* & */, 1 /* ' */,
320-
1 /* ( */, 1 /* ) */, 1 /* * */, 1 /* + */,
321-
1 /* , */, 1 /* - */, 1 /* . */, 0 /* / */,
322-
1 /* 0 */, 1 /* 1 */, 1 /* 2 */, 1 /* 3 */,
323-
1 /* 4 */, 1 /* 5 */, 1 /* 6 */, 1 /* 7 */,
324-
1 /* 8 */, 1 /* 9 */, 1 /* : */, 1 /* ; */,
325-
0 /* < */, 1 /* = */, 0 /* > */, 0 /* ? */,
326-
1 /* @ */, 1 /* A */, 1 /* B */, 1 /* C */,
327-
1 /* D */, 1 /* E */, 1 /* F */, 1 /* G */,
328-
1 /* H */, 1 /* I */, 1 /* J */, 1 /* K */,
329-
1 /* L */, 1 /* M */, 1 /* N */, 1 /* O */,
330-
1 /* P */, 1 /* Q */, 1 /* R */, 1 /* S */,
331-
1 /* T */, 1 /* U */, 1 /* V */, 1 /* W */,
332-
1 /* X */, 1 /* Y */, 1 /* Z */, 1 /* [ */,
333-
0 /* \ */, 1 /* ] */, 0 /* ^ */, 1 /* _ */,
334-
0 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */,
335-
1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */,
336-
1 /* h */, 1 /* i */, 1 /* j */, 1 /* k */,
337-
1 /* l */, 1 /* m */, 1 /* n */, 1 /* o */,
338-
1 /* p */, 1 /* q */, 1 /* r */, 1 /* s */,
339-
1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */,
340-
1 /* x */, 1 /* y */, 1 /* z */, 0 /* { */,
341-
0 /* | */, 0 /* } */, 1 /* ~ */, 0 /* DEL */,
342-
0 /* 0x80 */, 0 /* 0x81 */, 0 /* 0x82 */, 0 /* 0x83 */,
343-
0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */, 0 /* 0x87 */,
344-
0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
345-
0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */,
346-
0 /* 0x90 */, 0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */,
347-
0 /* 0x94 */, 0 /* 0x95 */, 0 /* 0x96 */, 0 /* 0x97 */,
348-
0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */, 0 /* 0x9b */,
349-
0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
350-
0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */,
351-
0 /* 0xa4 */, 0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */,
352-
0 /* 0xa8 */, 0 /* 0xa9 */, 0 /* 0xaa */, 0 /* 0xab */,
353-
0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */, 0 /* 0xaf */,
354-
0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
355-
0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */,
356-
0 /* 0xb8 */, 0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */,
357-
0 /* 0xbc */, 0 /* 0xbd */, 0 /* 0xbe */, 0 /* 0xbf */,
358-
0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */, 0 /* 0xc3 */,
359-
0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
360-
0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */,
361-
0 /* 0xcc */, 0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */,
362-
0 /* 0xd0 */, 0 /* 0xd1 */, 0 /* 0xd2 */, 0 /* 0xd3 */,
363-
0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */, 0 /* 0xd7 */,
364-
0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
365-
0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */,
366-
0 /* 0xe0 */, 0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */,
367-
0 /* 0xe4 */, 0 /* 0xe5 */, 0 /* 0xe6 */, 0 /* 0xe7 */,
368-
0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */, 0 /* 0xeb */,
369-
0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
370-
0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */,
371-
0 /* 0xf4 */, 0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */,
372-
0 /* 0xf8 */, 0 /* 0xf9 */, 0 /* 0xfa */, 0 /* 0xfb */,
373-
0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */, 0 /* 0xff */
374-
};
375-
376-
static int check_authority(const uint8_t *value, size_t len) {
377-
const uint8_t *last;
378-
for (last = value + len; value != last; ++value) {
379-
if (!VALID_AUTHORITY_CHARS[*value]) {
380-
return 0;
381-
}
382-
}
383-
return 1;
384-
}
385-
386308
static int check_scheme(const uint8_t *value, size_t len) {
387309
const uint8_t *last;
388310
if (len == 0) {
@@ -440,7 +362,7 @@ int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream,
440362

441363
if (nv->token == NGHTTP2_TOKEN__AUTHORITY ||
442364
nv->token == NGHTTP2_TOKEN_HOST) {
443-
rv = check_authority(nv->value->base, nv->value->len);
365+
rv = nghttp2_check_authority(nv->value->base, nv->value->len);
444366
} else if (nv->token == NGHTTP2_TOKEN__SCHEME) {
445367
rv = check_scheme(nv->value->base, nv->value->len);
446368
} else {

‎deps/nghttp2/lib/nghttp2_session.c

+21-17
Original file line numberDiff line numberDiff line change
@@ -3735,7 +3735,6 @@ static int session_end_stream_headers_received(nghttp2_session *session,
37353735

37363736
static int session_after_header_block_received(nghttp2_session *session) {
37373737
int rv = 0;
3738-
int call_cb = 1;
37393738
nghttp2_frame *frame = &session->iframe.frame;
37403739
nghttp2_stream *stream;
37413740

@@ -3789,21 +3788,25 @@ static int session_after_header_block_received(nghttp2_session *session) {
37893788
stream_id = frame->hd.stream_id;
37903789
}
37913790

3792-
call_cb = 0;
3793-
37943791
rv = session_handle_invalid_stream2(session, stream_id, frame,
37953792
NGHTTP2_ERR_HTTP_MESSAGING);
37963793
if (nghttp2_is_fatal(rv)) {
37973794
return rv;
37983795
}
3796+
3797+
if (frame->hd.type == NGHTTP2_HEADERS &&
3798+
(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)) {
3799+
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD);
3800+
/* Don't call nghttp2_session_close_stream_if_shut_rdwr
3801+
because RST_STREAM has been submitted. */
3802+
}
3803+
return 0;
37993804
}
38003805
}
38013806

3802-
if (call_cb) {
3803-
rv = session_call_on_frame_received(session, frame);
3804-
if (nghttp2_is_fatal(rv)) {
3805-
return rv;
3806-
}
3807+
rv = session_call_on_frame_received(session, frame);
3808+
if (nghttp2_is_fatal(rv)) {
3809+
return rv;
38073810
}
38083811

38093812
if (frame->hd.type != NGHTTP2_HEADERS) {
@@ -4942,7 +4945,6 @@ static int session_process_extension_frame(nghttp2_session *session) {
49424945
int nghttp2_session_on_data_received(nghttp2_session *session,
49434946
nghttp2_frame *frame) {
49444947
int rv = 0;
4945-
int call_cb = 1;
49464948
nghttp2_stream *stream;
49474949

49484950
/* We don't call on_frame_recv_callback if stream has been closed
@@ -4958,20 +4960,22 @@ int nghttp2_session_on_data_received(nghttp2_session *session,
49584960
if (session_enforce_http_messaging(session) &&
49594961
(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)) {
49604962
if (nghttp2_http_on_remote_end_stream(stream) != 0) {
4961-
call_cb = 0;
49624963
rv = nghttp2_session_add_rst_stream(session, stream->stream_id,
49634964
NGHTTP2_PROTOCOL_ERROR);
49644965
if (nghttp2_is_fatal(rv)) {
49654966
return rv;
49664967
}
4968+
4969+
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD);
4970+
/* Don't call nghttp2_session_close_stream_if_shut_rdwr because
4971+
RST_STREAM has been submitted. */
4972+
return 0;
49674973
}
49684974
}
49694975

4970-
if (call_cb) {
4971-
rv = session_call_on_frame_received(session, frame);
4972-
if (nghttp2_is_fatal(rv)) {
4973-
return rv;
4974-
}
4976+
rv = session_call_on_frame_received(session, frame);
4977+
if (nghttp2_is_fatal(rv)) {
4978+
return rv;
49754979
}
49764980

49774981
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
@@ -5409,8 +5413,8 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
54095413
case NGHTTP2_IB_READ_CLIENT_MAGIC:
54105414
readlen = nghttp2_min(inlen, iframe->payloadleft);
54115415

5412-
if (memcmp(NGHTTP2_CLIENT_MAGIC + NGHTTP2_CLIENT_MAGIC_LEN -
5413-
iframe->payloadleft,
5416+
if (memcmp(&NGHTTP2_CLIENT_MAGIC[NGHTTP2_CLIENT_MAGIC_LEN -
5417+
iframe->payloadleft],
54145418
in, readlen) != 0) {
54155419
return NGHTTP2_ERR_BAD_CLIENT_MAGIC;
54165420
}

0 commit comments

Comments
 (0)
Please sign in to comment.