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 <sage@inktank.com>
This commit is contained in:
Sage Weil 2012-09-28 07:15:07 -07:00
parent ae1c38f195
commit 797d3ccb7a

View File

@ -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);