Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
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
savoirfairelinux
opendht
Commits
4587c092
Commit
4587c092
authored
May 13, 2020
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
utils: always check length in findMapValue
parent
fc962458
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/utils.h
+8
-2
8 additions, 2 deletions
include/opendht/utils.h
src/utils.cpp
+2
-14
2 additions, 14 deletions
src/utils.cpp
with
10 additions
and
16 deletions
include/opendht/utils.h
+
8
−
2
View file @
4587c092
...
@@ -173,7 +173,13 @@ unpackMsg(Blob b) {
...
@@ -173,7 +173,13 @@ unpackMsg(Blob b) {
msgpack
::
unpacked
unpackMsg
(
Blob
b
);
msgpack
::
unpacked
unpackMsg
(
Blob
b
);
msgpack
::
object
*
findMapValue
(
const
msgpack
::
object
&
map
,
const
char
*
key
);
msgpack
::
object
*
findMapValue
(
const
msgpack
::
object
&
map
,
const
char
*
key
,
size_t
length
);
msgpack
::
object
*
findMapValue
(
const
msgpack
::
object
&
map
,
const
std
::
string
&
key
);
inline
msgpack
::
object
*
findMapValue
(
const
msgpack
::
object
&
map
,
const
char
*
key
)
{
return
findMapValue
(
map
,
key
,
strlen
(
key
));
}
inline
msgpack
::
object
*
findMapValue
(
const
msgpack
::
object
&
map
,
const
std
::
string
&
key
)
{
return
findMapValue
(
map
,
key
.
c_str
(),
key
.
size
());
}
}
// namespace dht
}
// namespace dht
This diff is collapsed.
Click to expand it.
src/utils.cpp
+
2
−
14
View file @
4587c092
...
@@ -277,28 +277,16 @@ unpackMsg(Blob b) {
...
@@ -277,28 +277,16 @@ unpackMsg(Blob b) {
}
}
msgpack
::
object
*
msgpack
::
object
*
findMapValue
(
const
msgpack
::
object
&
map
,
const
char
*
key
)
{
findMapValue
(
const
msgpack
::
object
&
map
,
const
char
*
key
,
size_t
key_length
)
{
if
(
map
.
type
!=
msgpack
::
type
::
MAP
)
throw
msgpack
::
type_error
();
if
(
map
.
type
!=
msgpack
::
type
::
MAP
)
throw
msgpack
::
type_error
();
for
(
unsigned
i
=
0
;
i
<
map
.
via
.
map
.
size
;
i
++
)
{
for
(
unsigned
i
=
0
;
i
<
map
.
via
.
map
.
size
;
i
++
)
{
auto
&
o
=
map
.
via
.
map
.
ptr
[
i
];
auto
&
o
=
map
.
via
.
map
.
ptr
[
i
];
if
(
o
.
key
.
type
==
msgpack
::
type
::
STR
if
(
o
.
key
.
type
==
msgpack
::
type
::
STR
&&
key_length
==
o
.
key
.
via
.
str
.
size
&&
std
::
strncmp
(
o
.
key
.
via
.
str
.
ptr
,
key
,
o
.
key
.
via
.
str
.
size
)
==
0
)
&&
std
::
strncmp
(
o
.
key
.
via
.
str
.
ptr
,
key
,
o
.
key
.
via
.
str
.
size
)
==
0
)
return
&
o
.
val
;
return
&
o
.
val
;
}
}
return
nullptr
;
return
nullptr
;
}
}
msgpack
::
object
*
findMapValue
(
const
msgpack
::
object
&
map
,
const
std
::
string
&
key
)
{
if
(
map
.
type
!=
msgpack
::
type
::
MAP
)
throw
msgpack
::
type_error
();
for
(
unsigned
i
=
0
;
i
<
map
.
via
.
map
.
size
;
i
++
)
{
auto
&
o
=
map
.
via
.
map
.
ptr
[
i
];
if
(
o
.
key
.
type
==
msgpack
::
type
::
STR
&&
key
.
size
()
==
o
.
key
.
via
.
str
.
size
&&
std
::
strncmp
(
o
.
key
.
via
.
str
.
ptr
,
key
.
data
(),
o
.
key
.
via
.
str
.
size
)
==
0
)
return
&
o
.
val
;
}
return
nullptr
;
}
}
}
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