Ignores SO_PEERSEC in getsockopt() when not supported 72/324872/2
authorDongsun Lee <ds73.lee@samsung.com>
Wed, 28 May 2025 05:20:12 +0000 (14:20 +0900)
committerDongsun Lee <ds73.lee@samsung.com>
Wed, 28 May 2025 05:47:13 +0000 (14:47 +0900)
Change-Id: If01a96756446a7ae5a711bce33229633e48867c0

src/rmi/socket.cpp

index 1950572d1a216e8f315d77f1dc6ada03729aa841..6ed53f4ca4e94d6a6587556fb35437918c6de09f 100644 (file)
@@ -46,14 +46,16 @@ void setCloseOnExec(int fd)
 Credentials getCredentials(int fd)
 {
        socklen_t length = 256;
-       char buf[256];
-       struct ucred cred;
+       char buf[256] = {0,};
+       struct ucred cred = {0,};
        socklen_t credsz = sizeof(cred);
        if (::getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &credsz)) {
                throw SocketException(klay::GetSystemErrorMessage());
        }
 
-       if (::getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &length)) {
+       int ret = ::getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &length);
+       // Ignores when the option is not supported by the protocol(ENOPROTOOPT).
+       if (ret != 0 && ret != ENOPROTOOPT) {
                throw SocketException(klay::GetSystemErrorMessage());
        }