From 797d3ccb7a5254413e745b164b856dbc76181149 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 28 Sep 2012 07:15:07 -0700 Subject: [PATCH] msg/Accepter: check getsockbyname() return value CID 717442: Other violation (CHECKED_RETURN) At (10): Calling function "getsockname(this->listen_sd, (sockaddr *)listen_addr.ss_addr(), &llen)" without checking return value. This library function may fail and return an error code. At (11): No check of the return value of "getsockname(this->listen_sd, (sockaddr *)listen_addr.ss_addr(), &llen)". Signed-off-by: Sage Weil --- src/msg/Accepter.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/msg/Accepter.cc b/src/msg/Accepter.cc index ce0b04a05ad..0c9917e0ab5 100644 --- a/src/msg/Accepter.cc +++ b/src/msg/Accepter.cc @@ -118,19 +118,22 @@ int Accepter::bind(entity_addr_t &bind_addr, int avoid_port1, int avoid_port2) // what port did we get? socklen_t llen = sizeof(listen_addr.ss_addr()); - getsockname(listen_sd, (sockaddr*)&listen_addr.ss_addr(), &llen); + rc = getsockname(listen_sd, (sockaddr*)&listen_addr.ss_addr(), &llen); + if (rc < 0) { + rc = -errno; + lderr(msgr->cct) << "accepter.bind failed getsockname: " << cpp_strerror(rc) << dendl; + return rc; + } ldout(msgr->cct,10) << "accepter.bind bound to " << listen_addr << dendl; // listen! rc = ::listen(listen_sd, 128); if (rc < 0) { - char buf[80]; - ldout(msgr->cct,0) << "accepter.bind unable to listen on " << listen_addr - << ": " << strerror_r(errno, buf, sizeof(buf)) << dendl; - cerr << "accepter.bind unable to listen on " << listen_addr - << ": " << strerror_r(errno, buf, sizeof(buf)) << std::endl; - return -errno; + rc = -errno; + lderr(msgr->cct) << "accepter.bind unable to listen on " << listen_addr + << ": " << cpp_strerror(rc) << dendl; + return rc; } msgr->set_myaddr(bind_addr);