Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Commits
ccc93e61
Commit
ccc93e61
authored
Sep 23, 2024
by
Georgy Moshkin
Browse files
Options
Downloads
Patches
Plain Diff
fix: used to allow use after free in RPC handlers sometimes
parent
4ef47673
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1308
fix: RouteBuilder::register now only supports Fn, not FnMut
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plugin/rpc/server.rs
+8
-4
8 additions, 4 deletions
src/plugin/rpc/server.rs
with
8 additions
and
4 deletions
src/plugin/rpc/server.rs
+
8
−
4
View file @
ccc93e61
...
@@ -6,6 +6,7 @@ use picoplugin::transport::rpc::server::FfiRpcHandler;
...
@@ -6,6 +6,7 @@ use picoplugin::transport::rpc::server::FfiRpcHandler;
use
picoplugin
::
util
::
RegionBuffer
;
use
picoplugin
::
util
::
RegionBuffer
;
use
std
::
collections
::
hash_map
::
Entry
;
use
std
::
collections
::
hash_map
::
Entry
;
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
rc
::
Rc
;
use
tarantool
::
error
::
BoxError
;
use
tarantool
::
error
::
BoxError
;
use
tarantool
::
error
::
Error
as
TntError
;
use
tarantool
::
error
::
Error
as
TntError
;
use
tarantool
::
error
::
TarantoolErrorCode
;
use
tarantool
::
error
::
TarantoolErrorCode
;
...
@@ -54,8 +55,11 @@ pub fn proc_rpc_dispatch_impl(args: &RawBytes) -> Result<&'static RawBytes, TntE
...
@@ -54,8 +55,11 @@ pub fn proc_rpc_dispatch_impl(args: &RawBytes) -> Result<&'static RawBytes, TntE
}
}
};
};
// SAFETY: safe because keys don't leak
// SAFETY: safe because
let
maybe_handler
=
unsafe
{
handlers_mut
()
.get
(
&
key
)
};
// - keys don't leak
// - we don't hold on to a reference to the global data, and other fibers
// may safely mutate the HANDLERS hashmap.
let
maybe_handler
=
unsafe
{
handlers_mut
()
.get
(
&
key
)
.cloned
()
};
let
Some
(
handler
)
=
maybe_handler
else
{
let
Some
(
handler
)
=
maybe_handler
else
{
#[rustfmt::skip]
#[rustfmt::skip]
...
@@ -103,7 +107,7 @@ pub fn proc_rpc_dispatch(args: &RawBytes) -> Result<&'static RawBytes, TntError>
...
@@ -103,7 +107,7 @@ pub fn proc_rpc_dispatch(args: &RawBytes) -> Result<&'static RawBytes, TntError>
static
mut
HANDLERS
:
Option
<
RpcHandlerMap
>
=
None
;
static
mut
HANDLERS
:
Option
<
RpcHandlerMap
>
=
None
;
type
RpcHandlerMap
=
HashMap
<
RpcHandlerKey
<
'static
>
,
FfiRpcHandler
>
;
type
RpcHandlerMap
=
HashMap
<
RpcHandlerKey
<
'static
>
,
Rc
<
FfiRpcHandler
>
>
;
#[derive(Debug,
Clone,
PartialEq,
Eq,
Hash)]
#[derive(Debug,
Clone,
PartialEq,
Eq,
Hash)]
struct
RpcHandlerKey
<
'a
>
{
struct
RpcHandlerKey
<
'a
>
{
...
@@ -194,7 +198,7 @@ pub fn register_rpc_handler(handler: FfiRpcHandler) -> Result<(), BoxError> {
...
@@ -194,7 +198,7 @@ pub fn register_rpc_handler(handler: FfiRpcHandler) -> Result<(), BoxError> {
handler
.version
(),
handler
.version
(),
handler
.path
(),
handler
.path
(),
);
);
entry
.insert
(
handler
);
entry
.insert
(
Rc
::
new
(
handler
)
)
;
Ok
(())
Ok
(())
}
}
...
...
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