Re: [PATCH v4] staging: wlags49_h2: strncpy, need checking the memory length

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 15, 2013 at 03:17:36PM +0800, Chen Gang wrote:
> On 05/15/2013 02:48 PM, Dan Carpenter wrote:
> > On Wed, May 15, 2013 at 10:51:58AM +0800, Chen Gang wrote:
> >> > 
> >> > HCF_MAX_NAME_LEN is 32, which may less than ''probe_rsp->rawData[1]'',
> >> > so need check the length when copy to ssid.
> >> > 
> >> > Type of 'probe_rsp->rawData[1]' is 'hcf_8' which is 'unsigned char',
> >> > it will compare with 'int', so use min_t() to cast to 'int' to avoid
> >> > related warning.
> >> > 
> >> > If use min(), it has '(void) (&_min1 == &_min2);', so if no type cast,
> >> > the compiler will report 'pointer types lacks a cast':
> >> > 
> >> >   drivers/staging/wlags49_h2/wl_main.c:3174:122: warning: comparison of distinct pointer types lacks a cast [enabled by default]
> >> > 
> >> > 
> >> > 
> >> > Signed-off-by: root <root@xxxxxxxxxxxxxxxxxxx>
> >                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > 
> > Oops.
> > 
> > Of course, I wish you had used min_t(u8, for the reasons I described
> > before but int also works fine.
> 
> The 2 variables for comparing: one is 'u8', the other is 'int'. Since
> 'int' is 'bigger' than 'u8', I like cast to 'int' (it is the 'default
> habit') ;-)
> 
> Could you describe the details again for why 'u8' is better than 'int' ?
> 

I explained this at length in an earlier email but here is the short
version again.  There are two bugs people introduce with min_t()
casting.

1) Casting high unsigned values to negative.
2) Truncating the value.

I tend to worry more about casting to negative because those are
more common and have worse effects for security.  In this case,
either int or u8 work, but when someone audits the code the cast to
int is a red flag and needs to be reviewed.

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux