Fix issue detected by static analysis tool 60/269560/5
authorInHong Han <inhong1.han@samsung.com>
Tue, 18 Jan 2022 07:41:34 +0000 (16:41 +0900)
committerInHong Han <inhong1.han@samsung.com>
Wed, 19 Jan 2022 07:43:48 +0000 (16:43 +0900)
Time of check time of use (TOCTOU)

Change-Id: I2e762e6170d14e423c855df39d3795e88e0c8cc2

ism/src/scim_socket.cpp

index d84a0ea..4ae1c3f 100644 (file)
@@ -623,20 +623,14 @@ public:
                 // by connecting to it.
                 SCIM_DEBUG_SOCKET (2) << "Try to remove the broken socket file: " << data_un->sun_path << "\n";
 
-                if (::access (data_un->sun_path, F_OK) == 0) {
-                    SocketClient tmp_socket (addr);
-
-                    if (!tmp_socket.is_connected ()) {
-                        struct stat statbuf;
-
-                        // If it's a socket file, then
-                        // delete it.
-                        if (::stat (data_un->sun_path, &statbuf) == 0 && S_ISSOCK (statbuf.st_mode))
-                            ::unlink (data_un->sun_path);
-                    }
-
-                    tmp_socket.close ();
+                SocketClient tmp_socket (addr);
+                if (!tmp_socket.is_connected ()) {
+                    LOGE ("the connection is broken");
+                    if (::unlink (data_un->sun_path) != 0)
+                        LOGE ("unlink() failed");
                 }
+
+                tmp_socket.close ();
             }
 
             if (::bind (m_id, data, len) == 0) {