Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
05a04e02
Commit
05a04e02
authored
Sep 22, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix use-after-free in new HTTP client code.
parent
d10f8eab
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
2 deletions
+37
-2
http.c++
c++/src/kj/compat/http.c++
+37
-2
No files found.
c++/src/kj/compat/http.c++
View file @
05a04e02
...
@@ -2866,6 +2866,36 @@ private:
...
@@ -2866,6 +2866,36 @@ private:
kj
::
Own
<
kj
::
AsyncInputStream
>
inner
;
kj
::
Own
<
kj
::
AsyncInputStream
>
inner
;
};
};
class
AttachmentWebSocket
final
:
public
WebSocket
{
// An WebSocket which also owns some separate object, released when the stream is freed.
public
:
AttachmentWebSocket
(
kj
::
Own
<
WebSocket
>
inner
,
kj
::
Own
<
kj
::
Refcounted
>
attachment
)
:
attachment
(
kj
::
mv
(
attachment
)),
inner
(
kj
::
mv
(
inner
))
{}
kj
::
Promise
<
void
>
send
(
kj
::
ArrayPtr
<
const
byte
>
message
)
override
{
return
inner
->
send
(
message
);
}
kj
::
Promise
<
void
>
send
(
kj
::
ArrayPtr
<
const
char
>
message
)
override
{
return
inner
->
send
(
message
);
}
kj
::
Promise
<
void
>
close
(
uint16_t
code
,
kj
::
StringPtr
reason
)
override
{
return
inner
->
close
(
code
,
reason
);
}
kj
::
Promise
<
void
>
disconnect
()
override
{
return
inner
->
disconnect
();
}
kj
::
Promise
<
Message
>
receive
()
override
{
return
inner
->
receive
();
}
private
:
// Note that it's important that `inner` be destroyed first since it typically depends on
// `attachment`.
kj
::
Own
<
kj
::
Refcounted
>
attachment
;
kj
::
Own
<
WebSocket
>
inner
;
};
class
NetworkAddressHttpClient
final
:
public
HttpClient
{
class
NetworkAddressHttpClient
final
:
public
HttpClient
{
public
:
public
:
NetworkAddressHttpClient
(
kj
::
Timer
&
timer
,
HttpHeaderTable
&
responseHeaderTable
,
NetworkAddressHttpClient
(
kj
::
Timer
&
timer
,
HttpHeaderTable
&
responseHeaderTable
,
...
@@ -2912,8 +2942,13 @@ public:
...
@@ -2912,8 +2942,13 @@ public:
kj
::
heap
<
AttachmentInputStream
>
(
kj
::
mv
(
body
),
kj
::
mv
(
refcounted
)));
kj
::
heap
<
AttachmentInputStream
>
(
kj
::
mv
(
body
),
kj
::
mv
(
refcounted
)));
}
}
KJ_CASE_ONEOF
(
ws
,
kj
::
Own
<
WebSocket
>
)
{
KJ_CASE_ONEOF
(
ws
,
kj
::
Own
<
WebSocket
>
)
{
// We actually don't need to attach the HttpClient to the WebSocket -- our HttpClient
// The only reason we need to attach the client to the WebSocket is because otherwise
// implementation transfers ownership of the connection into the WebSocket.
// the response headers will be deleted prematurely. Otherwise, the WebSocket has taken
// ownership of the connection.
//
// TODO(perf): Maybe we could transfer ownership of the response headers specifically?
response
.
webSocketOrBody
.
init
<
kj
::
Own
<
WebSocket
>>
(
kj
::
heap
<
AttachmentWebSocket
>
(
kj
::
mv
(
ws
),
kj
::
mv
(
refcounted
)));
}
}
}
}
return
kj
::
mv
(
response
);
return
kj
::
mv
(
response
);
...
...
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