From 2182bc963d2e0fc12a94adfdf92c7b31d593074e Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Sat, 25 Jul 2015 17:46:46 +0800 Subject: [PATCH] check for potential unsigned integer wraparound before adding --- src/msg.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/msg.cpp b/src/msg.cpp index 07ce88e4..d8519f32 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -103,8 +103,9 @@ int zmq::msg_t::init_size (size_t size_) u.lmsg.type = type_lmsg; u.lmsg.flags = 0; u.lmsg.routing_id = 0; - u.lmsg.content = - (content_t*) malloc (sizeof (content_t) + size_); + u.lmsg.content = NULL; + if (sizeof (content_t) + size_ > size_) + u.lmsg.content = (content_t*) malloc (sizeof (content_t) + size_); if (unlikely (!u.lmsg.content)) { errno = ENOMEM; return -1;