From aab1ad8b3d6ef6f386d62825f2bebd7d731d3a32 Mon Sep 17 00:00:00 2001 From: Jaemin Ryu Date: Tue, 26 May 2020 10:41:57 +0900 Subject: Fix ASAN build error Change-Id: I4ff2c4059b41253c1fc1cf85f4458aecc12061be Signed-off-by: Jaemin Ryu --- tools/tests/groups/ipc.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/tests/groups/ipc.cpp b/tools/tests/groups/ipc.cpp index fec0808..cfd5b66 100644 --- a/tools/tests/groups/ipc.cpp +++ b/tools/tests/groups/ipc.cpp @@ -188,6 +188,12 @@ public: struct sockaddr_un addr; std::thread client; + if (sockaddr.size() >= sizeof(sockaddr_un::sun_path)) { + Display::printError(); + Display::printResult(Display::FAIL, "Address too long"); + return; + } + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { Display::printError(); Display::printResult(Display::FAIL, "useSocket positive"); @@ -196,7 +202,7 @@ public: memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, sockaddr.c_str(), sizeof(sockaddr_un::sun_path)); + strncpy(addr.sun_path, sockaddr.c_str(), sizeof(sockaddr_un::sun_path) - 1); addr.sun_path[sizeof(sockaddr_un::sun_path) - 1] = '\0'; if (bind(fd, reinterpret_cast(&addr), sizeof(struct sockaddr_un)) == -1) { @@ -218,6 +224,13 @@ public: std::string message("audit socket event testing"); struct sockaddr_un serveraddr; + + if (sockaddr.size() >= sizeof(sockaddr_un::sun_path)) { + Display::printError(); + Display::printResult(Display::FAIL, "Address too long"); + return; + } + if ((clientFd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { Display::printError(); return; @@ -225,7 +238,7 @@ public: memset(&serveraddr, 0, sizeof(serveraddr)); serveraddr.sun_family = AF_UNIX; - strncpy(serveraddr.sun_path, sockaddr.c_str(), sizeof(sockaddr_un::sun_path)); + strncpy(serveraddr.sun_path, sockaddr.c_str(), sizeof(sockaddr_un::sun_path) - 1); serveraddr.sun_path[sizeof(sockaddr_un::sun_path) - 1] = '\0'; if (connect(clientFd, reinterpret_cast(&serveraddr), sizeof(serveraddr)) == -1) { -- cgit v1.2.3