Skip to content

Commit

Permalink
Problem: UB in message_t constructor
Browse files Browse the repository at this point in the history
Solution: Add check to guard against passing null to memcpy
  • Loading branch information
gummif committed Apr 5, 2020
1 parent a3e5b54 commit 1793a5b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,12 @@ class message_t
int rc = zmq_msg_init_size(&msg, size_);
if (rc != 0)
throw error_t();
memcpy(data(), data_, size_);
if (size_)
{
// this constructor allows (nullptr, 0),
// memcpy with a null pointer is UB
memcpy(data(), data_, size_);
}
}

message_t(void *data_, size_t size_, free_fn *ffn_, void *hint_ = ZMQ_NULLPTR)
Expand Down

0 comments on commit 1793a5b

Please sign in to comment.