Fix SVACE issue 55/321255/1
authorAdam Michalski <a.michalski2@partner.samsung.com>
Fri, 29 Nov 2024 10:19:57 +0000 (11:19 +0100)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Fri, 29 Nov 2024 10:30:46 +0000 (11:30 +0100)
WID:12134324 Result of sizeof should not be assigned to 4 byte data type

socklen_t is typically a type that represents the length of socket-related
structures. It is defined as an integer type, and its size may vary between
platforms (e.g., 4 bytes on some systems, 8 bytes on others).
The sizeof(sockaddr) expression returns a size of type size_t, which is
often 8 bytes on 64-bit platforms. Assigning a size_t value (potentially
8 bytes) to a socklen_t (potentially 4 bytes) might cause truncation,
leading to this static analyzer warning.

While this is unlikely to cause actual issues in practice (since the size of
struct sockaddr_un is typically within the range of socklen_t), the static
analyzer points out the theoretical possibility of a mismatch.

Change-Id: I1c51d47b742e7cfeaa508a4e1f1906d8b123d3f0

src/plugin/plugin.c

index 73d49900da203d8cc24cc98c0291cf465effb592..decd3a50c44e546a80630b0a94946bc50e06c96a 100644 (file)
@@ -58,7 +58,7 @@ static int resource_create_and_connect_sock(void)
 
        sockaddr.sun_family = AF_UNIX;
        strncpy(sockaddr.sun_path, SOCK_PATH, strlen(SOCK_PATH) + 1);
-       len = sizeof(sockaddr);
+       len = (socklen_t)sizeof(sockaddr);
 
        if (connect(sock, (struct sockaddr *)&sockaddr, len) < 0) {
                _E("[CPU-BOOSTING-PLUGIN] Failed to connect to the resourced module");