[PATCH] Fix improper use of default interface speed

Stefan Metzmacher metze at samba.org
Sat Feb 13 08:24:12 UTC 2016


Am 12.02.2016 um 21:32 schrieb Michael Adam:
> On 2016-02-12 at 22:16 +0530, Anoop C S wrote:
>> On Thu, 2016-02-11 at 13:27 +0100, Michael Adam wrote:
>>> On 2016-02-11 at 17:36 +0530, Anoop C S wrote:
>>>> From deeaf44850ba63d9566379f50ee7603f43b64d97 Mon Sep 17 00:00:00
>>>> 2001
>>>> From: Anoop C S <anoopcs at redhat.com>
>>>> Date: Thu, 11 Feb 2016 14:55:55 +0530
>>>> Subject: [PATCH] lib/socket: Fix improper use of default interface
>>>> speed
>>>>
>>>> _get_interfaces() function from interfaces.c uses if_speed
>>>> variable to store interface speed and is initialized with a
>>>> default value at start. But if_speed populated via one
>>>> iteration for a specific IP address will be treated as the
>>>> default value for next iteration which is wrong. Therefore
>>>> change is to move the initialization cum declaration of
>>>> if_speed inside iteration of IP addresses loop.
>>>>
>>>> Signed-off-by: Anoop C S <anoopcs at redhat.com>
>>>> ---
>>>>  lib/socket/interfaces.c | 2 +-
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/lib/socket/interfaces.c b/lib/socket/interfaces.c
>>>> index cf094f0..7ee5707 100644
>>>> --- a/lib/socket/interfaces.c
>>>> +++ b/lib/socket/interfaces.c
>>>> @@ -184,7 +184,6 @@ static int _get_interfaces(TALLOC_CTX *mem_ctx,
>>>> struct iface_struct **pifaces)
>>>>  	int count;
>>>>  	int total = 0;
>>>>  	size_t copy_size;
>>>> -	uint64_t if_speed = 1000 * 1000 * 1000; /* 1GBit */
>>>>  
>>>>  	if (getifaddrs(&iflist) < 0) {
>>>>  		return -1;
>>>> @@ -268,6 +267,7 @@ static int _get_interfaces(TALLOC_CTX *mem_ctx,
>>>> struct iface_struct **pifaces)
>>>>  				"%s\n", ifptr->ifa_name,
>>>> strerror(errno));
>>>>  		}
>>>>  
>>>> +		uint64_t if_speed = 1000 * 1000 * 1000; /* 1Gbps
>>>> */
>>>
>>> This should go to the top of the block.
>>> Declaring the variable inside the block of scope is good,
>>> but inside the block (just as in functions) the rule
>>> 'first declaration, then code' holds.
>>>
>>
>> Done. Please see the updated patch.
> 
> Reviewed-by: me

And me, but please file a bug report and add the BUG: ... url to
the commit message, we also need this in 4.4

Thanks!
metze

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160213/b7de95c0/signature.sig>


More information about the samba-technical mailing list