mirror of
https://github.com/ceph/ceph
synced 2024-12-30 07:23:11 +00:00
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:
parent
ae1c38f195
commit
797d3ccb7a
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user