Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TLMSP curl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CYBER - Cyber Security
TS 103 523 MSP
TLMSP
TLMSP curl
Commits
0ea9f700
Commit
0ea9f700
authored
11 years ago
by
Tatsuhiro Tsujikawa
Committed by
Daniel Stenberg
11 years ago
Browse files
Options
Downloads
Patches
Plain Diff
http2: handle incoming data larger than remaining buffer
parent
4082dc9d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/http.h
+4
-0
4 additions, 0 deletions
lib/http.h
lib/http2.c
+44
-17
44 additions, 17 deletions
lib/http2.c
with
48 additions
and
17 deletions
lib/http.h
+
4
−
0
View file @
0ea9f700
...
...
@@ -168,6 +168,10 @@ struct http_conn {
size_t
nread_header_recvbuf
;
/* number of bytes in header_recvbuf
fed into upper layer */
int32_t
stream_id
;
/* stream we are interested in */
const
uint8_t
*
data
;
/* pointer to data chunk, received in
on_data_chunk */
size_t
datalen
;
/* the number of bytes left in data */
char
*
inbuf
;
/* buffer to receive data from underlying socket */
#else
int
unused
;
/* prevent a compiler warning */
#endif
...
...
This diff is collapsed.
Click to expand it.
lib/http2.c
+
44
−
17
View file @
0ea9f700
...
...
@@ -166,6 +166,7 @@ static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
{
struct
connectdata
*
conn
=
(
struct
connectdata
*
)
userp
;
struct
http_conn
*
c
=
&
conn
->
proto
.
httpc
;
size_t
nread
;
(
void
)
session
;
(
void
)
flags
;
(
void
)
data
;
...
...
@@ -176,16 +177,19 @@ static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
return
0
;
}
if
(
len
<=
c
->
len
)
{
memcpy
(
c
->
mem
,
data
,
len
);
c
->
mem
+=
len
;
c
->
len
-=
len
;
}
else
{
infof
(
conn
->
data
,
"EEEEEEK: %d > %d
\n
"
,
len
,
c
->
len
);
/* return NGHTTP2_ERR_PAUSE; */
}
nread
=
c
->
len
<
len
?
c
->
len
:
len
;
memcpy
(
c
->
mem
,
data
,
nread
);
c
->
mem
+=
nread
;
c
->
len
-=
nread
;
infof
(
conn
->
data
,
"%zu data written
\n
"
,
nread
);
if
(
nread
<
len
)
{
c
->
data
=
data
+
nread
;
c
->
datalen
=
len
-
nread
;
return
NGHTTP2_ERR_PAUSE
;
}
return
0
;
}
...
...
@@ -330,14 +334,22 @@ static nghttp2_settings_entry settings[] = {
{
NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE
,
NGHTTP2_INITIAL_WINDOW_SIZE
},
};
#define H2_BUFSIZE 4096
/*
* Initialize nghttp2 for a Curl connection
*/
CURLcode
Curl_http2_init
(
struct
connectdata
*
conn
)
{
CURLcode
Curl_http2_init
(
struct
connectdata
*
conn
)
{
if
(
!
conn
->
proto
.
httpc
.
h2
)
{
int
rc
;
conn
->
proto
.
httpc
.
inbuf
=
malloc
(
H2_BUFSIZE
);
if
(
conn
->
proto
.
httpc
.
inbuf
==
NULL
)
return
CURLE_OUT_OF_MEMORY
;
/* The nghttp2 session is not yet setup, do it */
int
rc
=
nghttp2_session_client_new
(
&
conn
->
proto
.
httpc
.
h2
,
&
callbacks
,
conn
);
rc
=
nghttp2_session_client_new
(
&
conn
->
proto
.
httpc
.
h2
,
&
callbacks
,
conn
);
if
(
rc
)
{
failf
(
conn
->
data
,
"Couldn't initialize nghttp2!"
);
return
CURLE_OUT_OF_MEMORY
;
/* most likely at least */
...
...
@@ -402,8 +414,6 @@ CURLcode Curl_http2_request_upgrade(Curl_send_buffer *req,
return
result
;
}
#define H2_BUFSIZE 4096
/*
* If the read would block (EWOULDBLOCK) we return -1. Otherwise we return
* a regular CURLcode value.
...
...
@@ -414,7 +424,6 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
CURLcode
rc
;
ssize_t
rv
;
ssize_t
nread
;
char
inbuf
[
H2_BUFSIZE
];
struct
http_conn
*
httpc
=
&
conn
->
proto
.
httpc
;
(
void
)
sockindex
;
/* we always do HTTP2 on sockindex 0 */
...
...
@@ -430,6 +439,21 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
return
ncopy
;
}
if
(
httpc
->
data
)
{
nread
=
len
<
httpc
->
datalen
?
len
:
httpc
->
datalen
;
memcpy
(
mem
,
httpc
->
data
,
nread
);
httpc
->
data
+=
nread
;
httpc
->
datalen
-=
nread
;
infof
(
conn
->
data
,
"%zu data written
\n
"
,
nread
);
if
(
httpc
->
datalen
==
0
)
{
httpc
->
data
=
NULL
;
httpc
->
datalen
=
0
;
}
return
nread
;
}
conn
->
proto
.
httpc
.
mem
=
mem
;
conn
->
proto
.
httpc
.
len
=
len
;
...
...
@@ -438,7 +462,7 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
rc
=
0
;
nread
=
((
Curl_recv
*
)
httpc
->
recv_underlying
)(
conn
,
FIRSTSOCKET
,
inbuf
,
H2_BUFSIZE
,
&
rc
);
httpc
->
inbuf
,
H2_BUFSIZE
,
&
rc
);
if
(
rc
==
CURLE_AGAIN
)
{
*
err
=
rc
;
...
...
@@ -452,7 +476,8 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
}
infof
(
conn
->
data
,
"nread=%zd
\n
"
,
nread
);
rv
=
nghttp2_session_mem_recv
(
httpc
->
h2
,
(
const
uint8_t
*
)
inbuf
,
nread
);
rv
=
nghttp2_session_mem_recv
(
httpc
->
h2
,
(
const
uint8_t
*
)
httpc
->
inbuf
,
nread
);
if
(
nghttp2_is_fatal
((
int
)
rv
))
{
failf
(
conn
->
data
,
"nghttp2_session_mem_recv() returned %d:%s
\n
"
,
...
...
@@ -612,6 +637,8 @@ int Curl_http2_switched(struct connectdata *conn)
httpc
->
closed
=
FALSE
;
httpc
->
header_recvbuf
=
Curl_add_buffer_init
();
httpc
->
nread_header_recvbuf
=
0
;
httpc
->
data
=
NULL
;
httpc
->
datalen
=
0
;
/* Put place holder for status line */
Curl_add_buffer
(
httpc
->
header_recvbuf
,
"HTTP/2.0 200
\r\n
"
,
14
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment