Fix ASAN build error 73/234373/1 accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix tizen_6.0 tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.114738 accepted/tizen/6.0/unified/hotfix/20201103.003149 accepted/tizen/unified/20200528.132954 submit/tizen/20200526.072729 submit/tizen_6.0/20201029.205104 submit/tizen_6.0_hotfix/20201102.192504 submit/tizen_6.0_hotfix/20201103.114804 tizen_6.0.m2_release
authorJaemin Ryu <jm77.ryu@samsung.com>
Tue, 26 May 2020 01:41:57 +0000 (10:41 +0900)
committerJaemin Ryu <jm77.ryu@samsung.com>
Tue, 26 May 2020 01:45:28 +0000 (10:45 +0900)
Change-Id: I4ff2c4059b41253c1fc1cf85f4458aecc12061be
Signed-off-by: Jaemin Ryu <jm77.ryu@samsung.com>
tools/tests/groups/ipc.cpp

index fec08087053d3adb1b93e0413d3fa516924d12ab..cfd5b660d4f2263c76d0f44313d09766edbf312d 100644 (file)
@@ -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<struct sockaddr *>(&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<struct sockaddr *>(&serveraddr), sizeof(serveraddr)) == -1) {