Skip to content

Commit

Permalink
Fix potential segfault in MSGQPubSocket::connect (sshane#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiubit authored May 20, 2020
1 parent 67fae6a commit c1a6d75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion messaging/impl_msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion messaging/msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c1a6d75

Please sign in to comment.