Re: [PATCH V2] Fix buffer size warning for strcpy

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

 



On Mon, 23 Aug 2021, Gal Ofri wrote:
> > You really should explain here why we change from filling with spaces to
> > filling with nuls.
> I guess that a commit-comment would still be needed, but I think that a
> more conventional approach could make it all clearer:
> 
> - memset(ve->name, ' ', 16);
> - if (name)
> -	strncpy(ve->name, name, 16);
> + int l = strnlen(ve->name, 16);
> + memcpy(ve->name, name, l);
> + if (l < 16) /* no null-termination expected when all the space is used */
> + 	ve->name[l] = '\0';

No, that would be wrong.  It doesn't clear the whole array.

NeilBrown



[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux