Skip to content

Commit 6da49eb

Browse files
committed
release: 2.1.3
1 parent 5abe39a commit 6da49eb

2 files changed

Lines changed: 97 additions & 33 deletions

File tree

include/llhttp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define LLHTTP_VERSION_MAJOR 2
55
#define LLHTTP_VERSION_MINOR 1
6-
#define LLHTTP_VERSION_PATCH 1
6+
#define LLHTTP_VERSION_PATCH 3
77

88
#ifndef LLHTTP_STRICT_MODE
99
# define LLHTTP_STRICT_MODE 0

src/llhttp.c

Lines changed: 96 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static const unsigned char llparse_blob7[] = {
4949
};
5050
#ifdef __SSE4_2__
5151
static const unsigned char ALIGN(16) llparse_blob8[] = {
52-
0x9, 0x9, ' ', '~', 0x80, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0,
52+
0x9, 0x9, ' ', '~', 0x80, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0,
5353
0x0, 0x0, 0x0, 0x0, 0x0
5454
};
5555
#endif /* __SSE4_2__ */
@@ -230,6 +230,38 @@ static llparse_match_t llparse__match_sequence_id(
230230
return res;
231231
}
232232

233+
static llparse_match_t llparse__match_sequence_to_lower(
234+
llhttp__internal_t* s, const unsigned char* p,
235+
const unsigned char* endp,
236+
const unsigned char* seq, uint32_t seq_len) {
237+
uint32_t index;
238+
llparse_match_t res;
239+
240+
index = s->_index;
241+
for (; p != endp; p++) {
242+
unsigned char current;
243+
244+
current = ((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p));
245+
if (current == seq[index]) {
246+
if (++index == seq_len) {
247+
res.status = kMatchComplete;
248+
goto reset;
249+
}
250+
} else {
251+
res.status = kMatchMismatch;
252+
goto reset;
253+
}
254+
}
255+
s->_index = index;
256+
res.status = kMatchPause;
257+
res.current = p;
258+
return res;
259+
reset:
260+
s->_index = 0;
261+
res.current = p;
262+
return res;
263+
}
264+
233265
static llparse_match_t llparse__match_sequence_to_lower_unsafe(
234266
llhttp__internal_t* s, const unsigned char* p,
235267
const unsigned char* endp,
@@ -1563,7 +1595,7 @@ static llparse_state_t llhttp__internal__run(
15631595
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
15641596
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
15651597
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1566-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1598+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
15671599
};
15681600
if (p == endp) {
15691601
return s_n_llhttp__internal__n_header_value_connection_token;
@@ -1618,7 +1650,7 @@ static llparse_state_t llhttp__internal__run(
16181650
if (p == endp) {
16191651
return s_n_llhttp__internal__n_header_value_connection_1;
16201652
}
1621-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob4, 4);
1653+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob4, 4);
16221654
p = match_seq.current;
16231655
switch (match_seq.status) {
16241656
case kMatchComplete: {
@@ -1642,7 +1674,7 @@ static llparse_state_t llhttp__internal__run(
16421674
if (p == endp) {
16431675
return s_n_llhttp__internal__n_header_value_connection_2;
16441676
}
1645-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob5, 9);
1677+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob5, 9);
16461678
p = match_seq.current;
16471679
switch (match_seq.status) {
16481680
case kMatchComplete: {
@@ -1666,7 +1698,7 @@ static llparse_state_t llhttp__internal__run(
16661698
if (p == endp) {
16671699
return s_n_llhttp__internal__n_header_value_connection_3;
16681700
}
1669-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob6, 6);
1701+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob6, 6);
16701702
p = match_seq.current;
16711703
switch (match_seq.status) {
16721704
case kMatchComplete: {
@@ -1688,7 +1720,7 @@ static llparse_state_t llhttp__internal__run(
16881720
if (p == endp) {
16891721
return s_n_llhttp__internal__n_header_value_connection;
16901722
}
1691-
switch (((*p) | 0x20)) {
1723+
switch (((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p))) {
16921724
case 9: {
16931725
p++;
16941726
goto s_n_llhttp__internal__n_header_value_connection;
@@ -1884,7 +1916,7 @@ static llparse_state_t llhttp__internal__run(
18841916
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
18851917
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
18861918
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1887-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1919+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
18881920
};
18891921
if (p == endp) {
18901922
return s_n_llhttp__internal__n_header_value;
@@ -1943,7 +1975,7 @@ static llparse_state_t llhttp__internal__run(
19431975
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
19441976
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
19451977
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1946-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1978+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
19471979
};
19481980
if (p == endp) {
19491981
return s_n_llhttp__internal__n_header_value_te_token;
@@ -2142,7 +2174,7 @@ static llparse_state_t llhttp__internal__run(
21422174
if (p == endp) {
21432175
return s_n_llhttp__internal__n_header_field_3;
21442176
}
2145-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob3, 6);
2177+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob3, 6);
21462178
p = match_seq.current;
21472179
switch (match_seq.status) {
21482180
case kMatchComplete: {
@@ -2167,7 +2199,7 @@ static llparse_state_t llhttp__internal__run(
21672199
if (p == endp) {
21682200
return s_n_llhttp__internal__n_header_field_4;
21692201
}
2170-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob11, 10);
2202+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob11, 10);
21712203
p = match_seq.current;
21722204
switch (match_seq.status) {
21732205
case kMatchComplete: {
@@ -2190,7 +2222,7 @@ static llparse_state_t llhttp__internal__run(
21902222
if (p == endp) {
21912223
return s_n_llhttp__internal__n_header_field_2;
21922224
}
2193-
switch (((*p) | 0x20)) {
2225+
switch (((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p))) {
21942226
case 'n': {
21952227
p++;
21962228
goto s_n_llhttp__internal__n_header_field_3;
@@ -2213,7 +2245,7 @@ static llparse_state_t llhttp__internal__run(
22132245
if (p == endp) {
22142246
return s_n_llhttp__internal__n_header_field_1;
22152247
}
2216-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob2, 2);
2248+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob2, 2);
22172249
p = match_seq.current;
22182250
switch (match_seq.status) {
22192251
case kMatchComplete: {
@@ -2237,7 +2269,7 @@ static llparse_state_t llhttp__internal__run(
22372269
if (p == endp) {
22382270
return s_n_llhttp__internal__n_header_field_5;
22392271
}
2240-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob12, 15);
2272+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob12, 15);
22412273
p = match_seq.current;
22422274
switch (match_seq.status) {
22432275
case kMatchComplete: {
@@ -2262,7 +2294,7 @@ static llparse_state_t llhttp__internal__run(
22622294
if (p == endp) {
22632295
return s_n_llhttp__internal__n_header_field_6;
22642296
}
2265-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob13, 16);
2297+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob13, 16);
22662298
p = match_seq.current;
22672299
switch (match_seq.status) {
22682300
case kMatchComplete: {
@@ -2287,7 +2319,7 @@ static llparse_state_t llhttp__internal__run(
22872319
if (p == endp) {
22882320
return s_n_llhttp__internal__n_header_field_7;
22892321
}
2290-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob14, 6);
2322+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob14, 6);
22912323
p = match_seq.current;
22922324
switch (match_seq.status) {
22932325
case kMatchComplete: {
@@ -2310,7 +2342,7 @@ static llparse_state_t llhttp__internal__run(
23102342
if (p == endp) {
23112343
return s_n_llhttp__internal__n_header_field;
23122344
}
2313-
switch (((*p) | 0x20)) {
2345+
switch (((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p))) {
23142346
case 'c': {
23152347
p++;
23162348
goto s_n_llhttp__internal__n_header_field_1;
@@ -6831,7 +6863,7 @@ static const unsigned char llparse_blob7[] = {
68316863
};
68326864
#ifdef __SSE4_2__
68336865
static const unsigned char ALIGN(16) llparse_blob8[] = {
6834-
0x9, 0x9, ' ', '~', 0x80, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0,
6866+
0x9, 0x9, ' ', '~', 0x80, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0,
68356867
0x0, 0x0, 0x0, 0x0, 0x0
68366868
};
68376869
#endif /* __SSE4_2__ */
@@ -7015,6 +7047,38 @@ static llparse_match_t llparse__match_sequence_id(
70157047
return res;
70167048
}
70177049

7050+
static llparse_match_t llparse__match_sequence_to_lower(
7051+
llhttp__internal_t* s, const unsigned char* p,
7052+
const unsigned char* endp,
7053+
const unsigned char* seq, uint32_t seq_len) {
7054+
uint32_t index;
7055+
llparse_match_t res;
7056+
7057+
index = s->_index;
7058+
for (; p != endp; p++) {
7059+
unsigned char current;
7060+
7061+
current = ((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p));
7062+
if (current == seq[index]) {
7063+
if (++index == seq_len) {
7064+
res.status = kMatchComplete;
7065+
goto reset;
7066+
}
7067+
} else {
7068+
res.status = kMatchMismatch;
7069+
goto reset;
7070+
}
7071+
}
7072+
s->_index = index;
7073+
res.status = kMatchPause;
7074+
res.current = p;
7075+
return res;
7076+
reset:
7077+
s->_index = 0;
7078+
res.current = p;
7079+
return res;
7080+
}
7081+
70187082
static llparse_match_t llparse__match_sequence_to_lower_unsafe(
70197083
llhttp__internal_t* s, const unsigned char* p,
70207084
const unsigned char* endp,
@@ -8294,7 +8358,7 @@ static llparse_state_t llhttp__internal__run(
82948358
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
82958359
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
82968360
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
8297-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
8361+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
82988362
};
82998363
if (p == endp) {
83008364
return s_n_llhttp__internal__n_header_value_connection_token;
@@ -8349,7 +8413,7 @@ static llparse_state_t llhttp__internal__run(
83498413
if (p == endp) {
83508414
return s_n_llhttp__internal__n_header_value_connection_1;
83518415
}
8352-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob4, 4);
8416+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob4, 4);
83538417
p = match_seq.current;
83548418
switch (match_seq.status) {
83558419
case kMatchComplete: {
@@ -8373,7 +8437,7 @@ static llparse_state_t llhttp__internal__run(
83738437
if (p == endp) {
83748438
return s_n_llhttp__internal__n_header_value_connection_2;
83758439
}
8376-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob5, 9);
8440+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob5, 9);
83778441
p = match_seq.current;
83788442
switch (match_seq.status) {
83798443
case kMatchComplete: {
@@ -8397,7 +8461,7 @@ static llparse_state_t llhttp__internal__run(
83978461
if (p == endp) {
83988462
return s_n_llhttp__internal__n_header_value_connection_3;
83998463
}
8400-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob6, 6);
8464+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob6, 6);
84018465
p = match_seq.current;
84028466
switch (match_seq.status) {
84038467
case kMatchComplete: {
@@ -8419,7 +8483,7 @@ static llparse_state_t llhttp__internal__run(
84198483
if (p == endp) {
84208484
return s_n_llhttp__internal__n_header_value_connection;
84218485
}
8422-
switch (((*p) | 0x20)) {
8486+
switch (((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p))) {
84238487
case 9: {
84248488
p++;
84258489
goto s_n_llhttp__internal__n_header_value_connection;
@@ -8615,7 +8679,7 @@ static llparse_state_t llhttp__internal__run(
86158679
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
86168680
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
86178681
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
8618-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
8682+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
86198683
};
86208684
if (p == endp) {
86218685
return s_n_llhttp__internal__n_header_value;
@@ -8674,7 +8738,7 @@ static llparse_state_t llhttp__internal__run(
86748738
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
86758739
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
86768740
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
8677-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
8741+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
86788742
};
86798743
if (p == endp) {
86808744
return s_n_llhttp__internal__n_header_value_te_token;
@@ -8873,7 +8937,7 @@ static llparse_state_t llhttp__internal__run(
88738937
if (p == endp) {
88748938
return s_n_llhttp__internal__n_header_field_3;
88758939
}
8876-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob3, 6);
8940+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob3, 6);
88778941
p = match_seq.current;
88788942
switch (match_seq.status) {
88798943
case kMatchComplete: {
@@ -8898,7 +8962,7 @@ static llparse_state_t llhttp__internal__run(
88988962
if (p == endp) {
88998963
return s_n_llhttp__internal__n_header_field_4;
89008964
}
8901-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob11, 10);
8965+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob11, 10);
89028966
p = match_seq.current;
89038967
switch (match_seq.status) {
89048968
case kMatchComplete: {
@@ -8921,7 +8985,7 @@ static llparse_state_t llhttp__internal__run(
89218985
if (p == endp) {
89228986
return s_n_llhttp__internal__n_header_field_2;
89238987
}
8924-
switch (((*p) | 0x20)) {
8988+
switch (((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p))) {
89258989
case 'n': {
89268990
p++;
89278991
goto s_n_llhttp__internal__n_header_field_3;
@@ -8944,7 +9008,7 @@ static llparse_state_t llhttp__internal__run(
89449008
if (p == endp) {
89459009
return s_n_llhttp__internal__n_header_field_1;
89469010
}
8947-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob2, 2);
9011+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob2, 2);
89489012
p = match_seq.current;
89499013
switch (match_seq.status) {
89509014
case kMatchComplete: {
@@ -8968,7 +9032,7 @@ static llparse_state_t llhttp__internal__run(
89689032
if (p == endp) {
89699033
return s_n_llhttp__internal__n_header_field_5;
89709034
}
8971-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob12, 15);
9035+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob12, 15);
89729036
p = match_seq.current;
89739037
switch (match_seq.status) {
89749038
case kMatchComplete: {
@@ -8993,7 +9057,7 @@ static llparse_state_t llhttp__internal__run(
89939057
if (p == endp) {
89949058
return s_n_llhttp__internal__n_header_field_6;
89959059
}
8996-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob13, 16);
9060+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob13, 16);
89979061
p = match_seq.current;
89989062
switch (match_seq.status) {
89999063
case kMatchComplete: {
@@ -9018,7 +9082,7 @@ static llparse_state_t llhttp__internal__run(
90189082
if (p == endp) {
90199083
return s_n_llhttp__internal__n_header_field_7;
90209084
}
9021-
match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob14, 6);
9085+
match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob14, 6);
90229086
p = match_seq.current;
90239087
switch (match_seq.status) {
90249088
case kMatchComplete: {
@@ -9041,7 +9105,7 @@ static llparse_state_t llhttp__internal__run(
90419105
if (p == endp) {
90429106
return s_n_llhttp__internal__n_header_field;
90439107
}
9044-
switch (((*p) | 0x20)) {
9108+
switch (((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p))) {
90459109
case 'c': {
90469110
p++;
90479111
goto s_n_llhttp__internal__n_header_field_1;

0 commit comments

Comments
 (0)