[PATCH 2/3] virNetSocketCheckProtocols: lookup IPv6 only if suspecting IPv6

Michal Prívozník mprivozn at redhat.com
Fri Jul 17 10:58:40 UTC 2020


On 7/17/20 12:33 PM, John Ferlan wrote:
> 
> 
> On 7/15/20 7:48 AM, Michal Privoznik wrote:
>> There is not much sense trying to disprove host is IPv6 capable
>> if we know after first round (getifaddrs()) that is is not.
>>
>> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>> ---
>>   src/rpc/virnetsocket.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
>> index b6bc3edc3b..b0d63f0f2c 100644
>> --- a/src/rpc/virnetsocket.c
>> +++ b/src/rpc/virnetsocket.c
>> @@ -205,7 +205,8 @@ int virNetSocketCheckProtocols(bool *hasIPv4,
>>       freeifaddrs(ifaddr);
>>   
>>   
>> -    if (virNetSocketCheckProtocolByLookup("::1", AF_INET6, hasIPv6) < 0)
>> +    if (hasIPv6 &&
> 
> For this and the subsequent hasIPv4 patch, Coverity complains that
> checking "if (hasIPv6)" is a REVERSE_INULL issue since a few lines above
> we have "*hasIPv4 = *hasIPv6 = false;" or individual setting to true.
> 
> This then should be "if (!*hasIPv6..." and of course the same for hasIPv4.
> 
> /me wonders what kind of slight optimization exists or anyone cares
> about in the ifaddr loop once both has* bool ptrs are proven true - it's
> not like there's a set to false...

D'oh! It should have been: if (*hasIPv6 && ..); because we are 
interested in the value of boolean, not its address. I'll post a patch 
shortly.

Michal




More information about the libvir-list mailing list