Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
434e80dc
Commit
434e80dc
authored
Jan 24, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Reset stream if TE header field contains other than trailer
parent
5c93a113
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
107 additions
and
1 deletion
+107
-1
src/http2.cc
src/http2.cc
+32
-0
src/http2.h
src/http2.h
+6
-0
src/http2_test.cc
src/http2_test.cc
+56
-0
src/http2_test.h
src/http2_test.h
+1
-0
src/shrpx-unittest.cc
src/shrpx-unittest.cc
+2
-0
src/shrpx_http2_upstream.cc
src/shrpx_http2_upstream.cc
+10
-1
No files found.
src/http2.cc
View file @
434e80dc
...
...
@@ -664,6 +664,38 @@ const Headers::value_type *get_header(const int *hdidx, int token,
return
&
nva
[
i
];
}
bool
check_http2_te
(
const
uint8_t
*
value
,
size_t
valuelen
)
{
auto
first
=
value
;
auto
last
=
first
+
valuelen
;
for
(;;)
{
if
(
first
==
last
)
{
return
true
;
}
auto
end_param
=
std
::
find
(
first
,
last
,
','
);
auto
len
=
end_param
-
first
;
if
(
!
util
::
istartsWith
(
reinterpret_cast
<
const
char
*>
(
first
),
len
,
"trailer"
))
{
return
false
;
}
if
(
len
==
sizeof
(
"trailer"
)
-
1
)
{
goto
next
;
}
switch
(
first
[
sizeof
(
"trailer"
)
-
1
])
{
case
' '
:
case
';'
:
goto
next
;
}
return
false
;
next:
if
(
end_param
==
last
)
{
return
true
;
}
first
=
std
::
find_if_not
(
end_param
+
1
,
last
,
[](
uint8_t
c
)
{
return
c
==
' '
||
c
==
'\t'
||
c
==
','
;
});
}
}
}
// namespace http2
}
// namespace nghttp2
src/http2.h
View file @
434e80dc
...
...
@@ -244,6 +244,12 @@ bool http2_mandatory_request_headers_presence(const int *hdidx);
const
Headers
::
value_type
*
get_header
(
const
int
*
hdidx
,
int
token
,
const
Headers
&
nva
);
// Returns true if TE request header field value |value| of length
// |valuelen| is empty or only contains "trailers". The valid header
// field value is "trailer" and optionally followed by "," or OWS for
// simplicity.
bool
check_http2_te
(
const
uint8_t
*
value
,
size_t
valuelen
);
}
// namespace http2
}
// namespace nghttp2
...
...
src/http2_test.cc
View file @
434e80dc
...
...
@@ -290,4 +290,60 @@ void test_http2_mandatory_request_headers_presence(void) {
CU_ASSERT
(
http2
::
http2_mandatory_request_headers_presence
(
hdidx
));
}
void
test_http2_check_http2_te
(
void
)
{
{
const
uint8_t
v
[]
=
"trailer"
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"Trailer"
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"trailer,"
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"trailer,,"
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"trailer, ,"
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"trailer, , "
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"trailer; q=0.9"
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"trailer ; q=0.9"
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"trailer ; q=0.9, trailer"
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"trailer ; q=0.9, trailer"
;
CU_ASSERT
(
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
// failure cases
{
const
uint8_t
v
[]
=
"trailer; q=0.9, gzip"
;
CU_ASSERT
(
!
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"traile"
;
CU_ASSERT
(
!
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
{
const
uint8_t
v
[]
=
"trailerr"
;
CU_ASSERT
(
!
http2
::
check_http2_te
(
v
,
sizeof
(
v
)
-
1
));
}
}
}
// namespace shrpx
src/http2_test.h
View file @
434e80dc
...
...
@@ -39,6 +39,7 @@ void test_http2_lookup_token(void);
void
test_http2_check_http2_pseudo_header
(
void
);
void
test_http2_http2_header_allowed
(
void
);
void
test_http2_mandatory_request_headers_presence
(
void
);
void
test_http2_check_http2_te
(
void
);
}
// namespace shrpx
...
...
src/shrpx-unittest.cc
View file @
434e80dc
...
...
@@ -93,6 +93,8 @@ int main(int argc, char *argv[]) {
shrpx
::
test_http2_http2_header_allowed
)
||
!
CU_add_test
(
pSuite
,
"http2_mandatory_request_headers_presence"
,
shrpx
::
test_http2_mandatory_request_headers_presence
)
||
!
CU_add_test
(
pSuite
,
"http2_check_http2_te"
,
shrpx
::
test_http2_check_http2_te
)
||
!
CU_add_test
(
pSuite
,
"downstream_index_request_headers"
,
shrpx
::
test_downstream_index_request_headers
)
||
!
CU_add_test
(
pSuite
,
"downstream_index_response_headers"
,
...
...
src/shrpx_http2_upstream.cc
View file @
434e80dc
...
...
@@ -207,7 +207,8 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame,
return
NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE
;
}
if
(
token
==
http2
::
HD_CONTENT_LENGTH
)
{
switch
(
token
)
{
case
http2
:
:
HD_CONTENT_LENGTH
:
{
auto
len
=
util
::
parse_uint
(
value
,
valuelen
);
if
(
len
==
-
1
)
{
if
(
upstream
->
error_reply
(
downstream
,
400
)
!=
0
)
{
...
...
@@ -222,6 +223,14 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame,
return
0
;
}
downstream
->
set_request_content_length
(
len
);
break
;
}
case
http2
:
:
HD_TE
:
if
(
!
http2
::
check_http2_te
(
value
,
valuelen
))
{
upstream
->
rst_stream
(
downstream
,
NGHTTP2_PROTOCOL_ERROR
);
return
NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE
;
}
break
;
}
downstream
->
add_request_header
(
name
,
namelen
,
value
,
valuelen
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment