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

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

 



On 19.08.2021 15:10, Nigel Croxon wrote:

+	memset(ve->name, '\0', sizeof(ve->name));
+	if (name) {
+		int l = strlen(ve->name);
+		if (l > 16)
+			l = 16;
+		memcpy(ve->name, name, l);
+	}

What about:
if (name)
	/*
	 * Name might not be null terminated.
	 */
	strncpy(ve->name, name, sizeof(ve->name));
else
	memset(ve->name, '\0', sizeof(ve->name));

If size is less than sizeof(ve->name) then strncpy will automatically
fill rest with "\0".

Mariusz



[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