Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
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
libzmq
Commits
f4fe375b
Commit
f4fe375b
authored
Feb 05, 2016
by
Brian Silverman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't call memcpy with 0 size and NULL pointer(s)
It's undefined behavior, and ubsan flags it.
parent
c9c9a777
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
18 additions
and
9 deletions
+18
-9
dealer.cpp
src/dealer.cpp
+2
-1
options.cpp
src/options.cpp
+2
-1
req.cpp
src/req.cpp
+2
-1
router.cpp
src/router.cpp
+2
-1
stream.cpp
src/stream.cpp
+2
-1
sub.cpp
src/sub.cpp
+2
-1
xsub.cpp
src/xsub.cpp
+2
-1
zmq.cpp
src/zmq.cpp
+4
-2
No files found.
src/dealer.cpp
View file @
f4fe375b
...
...
@@ -70,7 +70,8 @@ int zmq::dealer_t::xsetsockopt (int option_, const void *optval_,
size_t
optvallen_
)
{
bool
is_int
=
(
optvallen_
==
sizeof
(
int
));
int
value
=
is_int
?
*
((
int
*
)
optval_
)
:
0
;
int
value
=
0
;
if
(
is_int
)
memcpy
(
&
value
,
optval_
,
sizeof
(
int
));
switch
(
option_
)
{
case
ZMQ_PROBE_ROUTER
:
...
...
src/options.cpp
View file @
f4fe375b
...
...
@@ -92,7 +92,8 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
size_t
optvallen_
)
{
bool
is_int
=
(
optvallen_
==
sizeof
(
int
));
int
value
=
is_int
?
*
((
int
*
)
optval_
)
:
0
;
int
value
=
0
;
if
(
is_int
)
memcpy
(
&
value
,
optval_
,
sizeof
(
int
));
#if defined (ZMQ_ACT_MILITANT)
bool
malformed
=
true
;
// Did caller pass a bad option value?
#endif
...
...
src/req.cpp
View file @
f4fe375b
...
...
@@ -204,7 +204,8 @@ bool zmq::req_t::xhas_out ()
int
zmq
::
req_t
::
xsetsockopt
(
int
option_
,
const
void
*
optval_
,
size_t
optvallen_
)
{
bool
is_int
=
(
optvallen_
==
sizeof
(
int
));
int
value
=
is_int
?
*
((
int
*
)
optval_
)
:
0
;
int
value
=
0
;
if
(
is_int
)
memcpy
(
&
value
,
optval_
,
sizeof
(
int
));
switch
(
option_
)
{
case
ZMQ_REQ_CORRELATE
:
if
(
is_int
&&
value
>=
0
)
{
...
...
src/router.cpp
View file @
f4fe375b
...
...
@@ -97,7 +97,8 @@ int zmq::router_t::xsetsockopt (int option_, const void *optval_,
size_t
optvallen_
)
{
bool
is_int
=
(
optvallen_
==
sizeof
(
int
));
int
value
=
is_int
?
*
((
int
*
)
optval_
)
:
0
;
int
value
=
0
;
if
(
is_int
)
memcpy
(
&
value
,
optval_
,
sizeof
(
int
));
switch
(
option_
)
{
case
ZMQ_CONNECT_RID
:
...
...
src/stream.cpp
View file @
f4fe375b
...
...
@@ -178,7 +178,8 @@ int zmq::stream_t::xsetsockopt (int option_, const void *optval_,
size_t
optvallen_
)
{
bool
is_int
=
(
optvallen_
==
sizeof
(
int
));
int
value
=
is_int
?
*
((
int
*
)
optval_
)
:
0
;
int
value
=
0
;
if
(
is_int
)
memcpy
(
&
value
,
optval_
,
sizeof
(
int
));
switch
(
option_
)
{
case
ZMQ_CONNECT_RID
:
if
(
optval_
&&
optvallen_
)
{
...
...
src/sub.cpp
View file @
f4fe375b
...
...
@@ -62,7 +62,8 @@ int zmq::sub_t::xsetsockopt (int option_, const void *optval_,
else
if
(
option_
==
ZMQ_UNSUBSCRIBE
)
*
data
=
0
;
memcpy
(
data
+
1
,
optval_
,
optvallen_
);
if
(
optvallen_
>
0
)
memcpy
(
data
+
1
,
optval_
,
optvallen_
);
// Pass it further on in the stack.
int
err
=
0
;
...
...
src/xsub.cpp
View file @
f4fe375b
...
...
@@ -232,7 +232,8 @@ void zmq::xsub_t::send_subscription (unsigned char *data_, size_t size_,
errno_assert
(
rc
==
0
);
unsigned
char
*
data
=
(
unsigned
char
*
)
msg
.
data
();
data
[
0
]
=
1
;
memcpy
(
data
+
1
,
data_
,
size_
);
if
(
size_
>
0
)
memcpy
(
data
+
1
,
data_
,
size_
);
// Send it to the pipe.
bool
sent
=
pipe
->
write
(
&
msg
);
...
...
src/zmq.cpp
View file @
f4fe375b
...
...
@@ -393,7 +393,8 @@ int zmq_send (void *s_, const void *buf_, size_t len_, int flags_)
int
rc
=
zmq_msg_init_size
(
&
msg
,
len_
);
if
(
rc
!=
0
)
return
-
1
;
memcpy
(
zmq_msg_data
(
&
msg
),
buf_
,
len_
);
if
(
len_
>
0
)
memcpy
(
zmq_msg_data
(
&
msg
),
buf_
,
len_
);
zmq
::
socket_base_t
*
s
=
(
zmq
::
socket_base_t
*
)
s_
;
rc
=
s_sendmsg
(
s
,
&
msg
,
flags_
);
...
...
@@ -519,7 +520,8 @@ int zmq_recv (void *s_, void *buf_, size_t len_, int flags_)
// At the moment an oversized message is silently truncated.
// TODO: Build in a notification mechanism to report the overflows.
size_t
to_copy
=
size_t
(
nbytes
)
<
len_
?
size_t
(
nbytes
)
:
len_
;
memcpy
(
buf_
,
zmq_msg_data
(
&
msg
),
to_copy
);
if
(
to_copy
>
0
)
memcpy
(
buf_
,
zmq_msg_data
(
&
msg
),
to_copy
);
rc
=
zmq_msg_close
(
&
msg
);
errno_assert
(
rc
==
0
);
...
...
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