lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20121210224943.GT22569@mwanda>
Date:	Tue, 11 Dec 2012 01:49:43 +0300
From:	Dan Carpenter <dan.carpenter@...cle.com>
To:	Przemo Firszt <przemo@...szt.eu>
Cc:	Larry.Finger@...inger.net, florian.c.schilhabel@...glemail.com,
	greg@...ah.com, devel@...verdev.osuosl.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/5] rtl8712: replace min with min_t

On Mon, Dec 10, 2012 at 10:21:52PM +0000, Przemo Firszt wrote:
> Dnia 2012-12-10, pon o godzinie 12:41 +0300, Dan Carpenter pisze:
> > On Sun, Dec 09, 2012 at 10:15:09AM +0000, Przemo Firszt wrote:
> > > A clean up change suggested by checkpatch.pl
> > > 
> > > Signed-off-by: Przemo Firszt <przemo@...szt.eu>
> > > ---
> > >  drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 6 ++----
> > >  1 file changed, 2 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> > > index cdb51d7..b131b61 100644
> > > --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> > > +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> > > @@ -188,8 +188,7 @@ static inline char *translate_scan(struct _adapter *padapter,
> > >  	/* Add the ESSID */
> > >  	iwe.cmd = SIOCGIWESSID;
> > >  	iwe.u.data.flags = 1;
> > > -	iwe.u.data.length = (u16)min((u16)pnetwork->network.Ssid.SsidLength,
> > > -			    (u16)32);
> > > +	iwe.u.data.length = min_t(u16, pnetwork->network.Ssid.SsidLength, 32);
> > 
> > pnetwork->network.Ssid.SsidLength is a u32 so it would be better to
> > not truncate the upper bits away.  It's not going to cause a
> > problem, but its slightly messy.
> > 
> > This is a common problem where people take the type of
> > iwe.u.data.length and cast to that instead of considering the types
> > for the data they are comparing.
> > 
> Dan,
> Thanks for the comment!
> 
> iew.u.data.length is __u16
> 
> min_t is defined as:
> #define min_t(type, x, y) ({                    \
>         type __min1 = (x);                      \
>         type __min2 = (y);                      \
>         __min1 < __min2 ? __min1: __min2; })
> 
> If I understand you correctly I should use this:
> 
> iwe.u.data.length = min_t(u32, pnetwork->network.Ssid.SsidLength, 32);
> 
> the result of min_t is u32, but iwe.u.data.lenght is __u16
> 

At the end iwe.u.data.length is going to be a number between 0 and
32.  That can easily fit in 16 bits no problem.

The difference is that, imagine ->network.Ssid.SsidLength is larger
than u16 like 0x10001.  The cast to u16 changes it to 0x0001 which
is less than 32 so we would say the minimum is 1 when actually we
want to say 32 is the min.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ