From 0c0019b0e10d84d86c52b54c6da938eece2793df Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 23 Sep 2021 11:28:06 +0900 Subject: [PATCH] [CWE-252] Fixup the coverty issue [Problem] 1241492 Unchecked return value [Solution] check the return status of each close() call Change-Id: I97f174223ddd4d756e53e6800323e6e092397da6 Signed-off-by: Sung-jae Park --- .../libbeyond-discovery_dns_sd/src/discovery_client.cc | 9 +++++++-- .../libbeyond-discovery_dns_sd/src/discovery_server.cc | 9 +++++++-- .../libbeyond-discovery_dns_sd/src/nsdeventloop.cc | 17 ++++++++++++----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/subprojects/libbeyond-discovery_dns_sd/src/discovery_client.cc b/subprojects/libbeyond-discovery_dns_sd/src/discovery_client.cc index 7cd330b..a229c41 100644 --- a/subprojects/libbeyond-discovery_dns_sd/src/discovery_client.cc +++ b/subprojects/libbeyond-discovery_dns_sd/src/discovery_client.cc @@ -28,8 +28,13 @@ DiscoveryClient::DiscoveryClient() DiscoveryClient::~DiscoveryClient() { - close(eventPipe[1]); - close(eventPipe[0]); + if (close(eventPipe[1]) < 0) { + ErrPrintCode(errno, "close pipe[1]"); + } + + if (close(eventPipe[0]) < 0) { + ErrPrintCode(errno, "close pipe[0]"); + } } void DiscoveryClient::Destroy(void) diff --git a/subprojects/libbeyond-discovery_dns_sd/src/discovery_server.cc b/subprojects/libbeyond-discovery_dns_sd/src/discovery_server.cc index 87ae808..8c26bd0 100644 --- a/subprojects/libbeyond-discovery_dns_sd/src/discovery_server.cc +++ b/subprojects/libbeyond-discovery_dns_sd/src/discovery_server.cc @@ -32,8 +32,13 @@ DiscoveryServer::DiscoveryServer(const std::string name, uint16_t port) DiscoveryServer::~DiscoveryServer() { - close(eventPipe[1]); - close(eventPipe[0]); + if (close(eventPipe[1]) < 0) { + ErrPrintCode(errno, "close pipe[1]"); + } + + if (close(eventPipe[0]) < 0) { + ErrPrintCode(errno, "close pipe[0]"); + } } void DiscoveryServer::Destroy(void) diff --git a/subprojects/libbeyond-discovery_dns_sd/src/nsdeventloop.cc b/subprojects/libbeyond-discovery_dns_sd/src/nsdeventloop.cc index 34711d9..6684aa7 100644 --- a/subprojects/libbeyond-discovery_dns_sd/src/nsdeventloop.cc +++ b/subprojects/libbeyond-discovery_dns_sd/src/nsdeventloop.cc @@ -38,7 +38,10 @@ NsdEventLoop::~NsdEventLoop() } catch (NsdLoopException &e) { ErrPrintCode(e.returnValue, "quit() Fail"); } - close(epoll_fd); + + if (close(epoll_fd) < 0) { + ErrPrintCode(errno, "close epoll_fd"); + } } void NsdEventLoop::addWatch(int fd, eventCallback cb) @@ -85,10 +88,13 @@ void NsdEventLoop::run() ev.data.fd = looprun_fd; int ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, looprun_fd, &ev); if (ret < 0) { + ret = -errno; ErrPrintCode(errno, "epoll_ctl() Fail"); - close(looprun_fd); + if (close(looprun_fd) < 0) { + ErrPrintCode(errno, "close looprun_fd"); + } looprun_fd = -1; - throw NsdLoopException(-errno); + throw NsdLoopException(ret); } loop = std::thread([this]() { @@ -109,7 +115,6 @@ void NsdEventLoop::run() } else { ErrPrint("Invalid fd(%d), not found", events[i].data.fd); } - } } } @@ -132,7 +137,9 @@ void NsdEventLoop::quit() loop.join(); epoll_ctl(epoll_fd, EPOLL_CTL_DEL, looprun_fd, NULL); - close(looprun_fd); + if (close(looprun_fd) < 0) { + ErrPrintCode(errno, "close looprun_fd"); + } looprun_fd = -1; } -- 2.7.4