From c1a6d75d1dd6f996e33764ad46c2cc868469e09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Goli=C5=84ski?= Date: Thu, 21 May 2020 01:12:44 +0200 Subject: [PATCH] Fix potential segfault in MSGQPubSocket::connect (#45) --- messaging/impl_msgq.cc | 6 +++++- messaging/msgq.cc | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/messaging/impl_msgq.cc b/messaging/impl_msgq.cc index d37b8c986d7237..0a51d12c17ff4e 100644 --- a/messaging/impl_msgq.cc +++ b/messaging/impl_msgq.cc @@ -143,7 +143,11 @@ int MSGQPubSocket::connect(Context *context, std::string endpoint){ assert(context); q = new msgq_queue_t; - msgq_new_queue(q, endpoint.c_str(), DEFAULT_SEGMENT_SIZE); + int r = msgq_new_queue(q, endpoint.c_str(), DEFAULT_SEGMENT_SIZE); + if (r != 0){ + return r; + } + msgq_init_publisher(q); return 0; diff --git a/messaging/msgq.cc b/messaging/msgq.cc index 4ccd13df44527a..7c6210ead16c22 100644 --- a/messaging/msgq.cc +++ b/messaging/msgq.cc @@ -90,8 +90,10 @@ int msgq_new_queue(msgq_queue_t * q, const char * path, size_t size){ auto fd = open(full_path, O_RDWR | O_CREAT, 0777); delete[] full_path; - if (fd < 0) + if (fd < 0) { + std::cout << "Warning, could not open: " << full_path << std::endl; return -1; + } int rc = ftruncate(fd, size + sizeof(msgq_header_t)); if (rc < 0)