diff mbox series

[ovs-dev,v2,4/8] netlink-socket: Initialize socket family.

Message ID 20240820135549.1726748-5-mkp@redhat.com
State Changes Requested, archived
Delegated to: Ilya Maximets
Headers show
Series Address clang analyze warnings. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Mike Pattrick Aug. 20, 2024, 1:55 p.m. UTC
The Clang analyzer will alert on the use of uninitialized variable local
despite the fact that this should be set by a syscall.

To suppress the warning, this variable is now initialized.

Signed-off-by: Mike Pattrick <mkp@redhat.com>
---
 lib/netlink-socket.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Ilya Maximets Aug. 28, 2024, 12:40 a.m. UTC | #1
On 8/20/24 15:55, Mike Pattrick wrote:
> The Clang analyzer will alert on the use of uninitialized variable local
> despite the fact that this should be set by a syscall.
> 
> To suppress the warning, this variable is now initialized.
> 
> Signed-off-by: Mike Pattrick <mkp@redhat.com>
> ---
>  lib/netlink-socket.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c
> index 5cb1fc89a..737e49cfc 100644
> --- a/lib/netlink-socket.c
> +++ b/lib/netlink-socket.c
> @@ -233,6 +233,7 @@ nl_sock_create(int protocol, struct nl_sock **sockp)
>  
>      /* Obtain pid assigned by kernel. */
>      local_size = sizeof local;
> +    local.nl_family = AF_UNSPEC;

It feels strange to do that.  Just memset-ing the whole structure to 0 might
be a better choice.

>      if (getsockname(sock->fd, (struct sockaddr *) &local, &local_size) < 0) {
>          VLOG_ERR("getsockname: %s", ovs_strerror(errno));
>          goto error;
Eelco Chaudron Aug. 30, 2024, 1:19 p.m. UTC | #2
On 28 Aug 2024, at 2:40, Ilya Maximets wrote:

> On 8/20/24 15:55, Mike Pattrick wrote:
>> The Clang analyzer will alert on the use of uninitialized variable local
>> despite the fact that this should be set by a syscall.
>>
>> To suppress the warning, this variable is now initialized.
>>
>> Signed-off-by: Mike Pattrick <mkp@redhat.com>
>> ---
>>  lib/netlink-socket.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c
>> index 5cb1fc89a..737e49cfc 100644
>> --- a/lib/netlink-socket.c
>> +++ b/lib/netlink-socket.c
>> @@ -233,6 +233,7 @@ nl_sock_create(int protocol, struct nl_sock **sockp)
>>
>>      /* Obtain pid assigned by kernel. */
>>      local_size = sizeof local;
>> +    local.nl_family = AF_UNSPEC;
>
> It feels strange to do that.  Just memset-ing the whole structure to 0 might
> be a better choice.


As Simon mentioned in the v1 patch, this is more a problem of clang than our code, and wondering if we want to fix the code around it.

I just waved a couple of similar issues in Coverity.

However, if we do want to fix this, I would prefer the memset() as Ilya suggested.


I have not looked at clang-analyze for a while, but maybe there finally is a way to exclude results using an external file (rather than augment this inline).


>>      if (getsockname(sock->fd, (struct sockaddr *) &local, &local_size) < 0) {
>>          VLOG_ERR("getsockname: %s", ovs_strerror(errno));
>>          goto error;
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
diff mbox series

Patch

diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c
index 5cb1fc89a..737e49cfc 100644
--- a/lib/netlink-socket.c
+++ b/lib/netlink-socket.c
@@ -233,6 +233,7 @@  nl_sock_create(int protocol, struct nl_sock **sockp)
 
     /* Obtain pid assigned by kernel. */
     local_size = sizeof local;
+    local.nl_family = AF_UNSPEC;
     if (getsockname(sock->fd, (struct sockaddr *) &local, &local_size) < 0) {
         VLOG_ERR("getsockname: %s", ovs_strerror(errno));
         goto error;