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
321136b0
Commit
321136b0
authored
Jul 23, 2013
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttp2_hd: Don't malloc if namelen/valuelen are zero
parent
0000d3e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
8 deletions
+34
-8
lib/nghttp2_hd.c
lib/nghttp2_hd.c
+17
-8
tests/nghttp2_hd_test.c
tests/nghttp2_hd_test.c
+17
-0
No files found.
lib/nghttp2_hd.c
View file @
321136b0
...
@@ -118,19 +118,28 @@ int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t index, uint8_t flags,
...
@@ -118,19 +118,28 @@ int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t index, uint8_t flags,
{
{
int
rv
=
0
;
int
rv
=
0
;
if
(
flags
&
NGHTTP2_HD_FLAG_NAME_ALLOC
)
{
if
(
flags
&
NGHTTP2_HD_FLAG_NAME_ALLOC
)
{
ent
->
nv
.
name
=
nghttp2_memdup
(
name
,
namelen
);
if
(
namelen
==
0
)
{
if
(
ent
->
nv
.
name
==
NULL
)
{
/* We should not allow empty header field name */
rv
=
NGHTTP2_ERR_NOMEM
;
ent
->
nv
.
name
=
NULL
;
goto
fail
;
}
else
{
ent
->
nv
.
name
=
nghttp2_memdup
(
name
,
namelen
);
if
(
ent
->
nv
.
name
==
NULL
)
{
rv
=
NGHTTP2_ERR_NOMEM
;
goto
fail
;
}
}
}
}
else
{
}
else
{
ent
->
nv
.
name
=
name
;
ent
->
nv
.
name
=
name
;
}
}
if
(
flags
&
NGHTTP2_HD_FLAG_VALUE_ALLOC
)
{
if
(
flags
&
NGHTTP2_HD_FLAG_VALUE_ALLOC
)
{
ent
->
nv
.
value
=
nghttp2_memdup
(
value
,
valuelen
);
if
(
valuelen
==
0
)
{
if
(
ent
->
nv
.
value
==
NULL
)
{
ent
->
nv
.
value
=
NULL
;
rv
=
NGHTTP2_ERR_NOMEM
;
}
else
{
goto
fail2
;
ent
->
nv
.
value
=
nghttp2_memdup
(
value
,
valuelen
);
if
(
ent
->
nv
.
value
==
NULL
)
{
rv
=
NGHTTP2_ERR_NOMEM
;
goto
fail2
;
}
}
}
}
else
{
}
else
{
ent
->
nv
.
value
=
value
;
ent
->
nv
.
value
=
value
;
...
...
tests/nghttp2_hd_test.c
View file @
321136b0
...
@@ -57,6 +57,8 @@ void test_nghttp2_hd_deflate(void)
...
@@ -57,6 +57,8 @@ void test_nghttp2_hd_deflate(void)
nghttp2_nv
nva4
[]
=
{
MAKE_NV
(
":path"
,
"/style.css"
),
nghttp2_nv
nva4
[]
=
{
MAKE_NV
(
":path"
,
"/style.css"
),
MAKE_NV
(
"cookie"
,
"k1=v1"
),
MAKE_NV
(
"cookie"
,
"k1=v1"
),
MAKE_NV
(
"cookie"
,
"k1=v1"
)};
MAKE_NV
(
"cookie"
,
"k1=v1"
)};
nghttp2_nv
nva5
[]
=
{
MAKE_NV
(
":path"
,
"/style.css"
),
MAKE_NV
(
"x-nghttp2"
,
""
)};
size_t
nv_offset
=
12
;
size_t
nv_offset
=
12
;
uint8_t
*
buf
=
NULL
;
uint8_t
*
buf
=
NULL
;
size_t
buflen
=
0
;
size_t
buflen
=
0
;
...
@@ -125,6 +127,21 @@ void test_nghttp2_hd_deflate(void)
...
@@ -125,6 +127,21 @@ void test_nghttp2_hd_deflate(void)
nghttp2_nv_array_del
(
resnva
);
nghttp2_nv_array_del
(
resnva
);
nghttp2_hd_end_headers
(
&
inflater
);
nghttp2_hd_end_headers
(
&
inflater
);
/* Fifth headers includes empty value */
blocklen
=
nghttp2_hd_deflate_hd
(
&
deflater
,
&
buf
,
&
buflen
,
nv_offset
,
nva5
,
sizeof
(
nva5
)
/
sizeof
(
nghttp2_nv
));
CU_ASSERT
(
blocklen
>
0
);
nghttp2_hd_end_headers
(
&
deflater
);
CU_ASSERT
(
2
==
nghttp2_hd_inflate_hd
(
&
inflater
,
&
resnva
,
buf
+
nv_offset
,
blocklen
));
assert_nv_equal
(
nva5
,
resnva
,
2
);
nghttp2_nv_array_del
(
resnva
);
nghttp2_hd_end_headers
(
&
inflater
);
/* Cleanup */
free
(
buf
);
free
(
buf
);
nghttp2_hd_inflate_free
(
&
inflater
);
nghttp2_hd_inflate_free
(
&
inflater
);
nghttp2_hd_deflate_free
(
&
deflater
);
nghttp2_hd_deflate_free
(
&
deflater
);
...
...
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