[PATCH] Fix improper use of default interface speed

Anoop C S anoopcs at redhat.com
Fri Feb 12 16:46:56 UTC 2016


On Thu, 2016-02-11 at 13:27 +0100, Michael Adam wrote:
> On 2016-02-11 at 17:36 +0530, Anoop C S wrote:
> > Hi,
> > 
> > Please find the attached patch for fixing the issue that was
> > discovered
> > while fixing CID 1350009 related to default initialization of
> > interface
> > speed. See the commit message for detailed explanation.
> 
> Thanks Anoop,
> 
> Please see a comment inside down below.
> 
> Cheers - Michael
> 
> > 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.

> >  #ifdef HAVE_ETHTOOL
> >  		query_iface_speed_from_name(ifptr->ifa_name,
> > &if_speed);
> >  #endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-lib-socket-Fix-improper-use-of-default-interface-spe.patch
Type: text/x-patch
Size: 1519 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160212/a95068c7/0001-lib-socket-Fix-improper-use-of-default-interface-spe.bin>


More information about the samba-technical mailing list