Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: scsi_devinfo: cleanly zero-pad devinfo strings

Cleanly fill memory for "vendor" and "model" with 0-bytes for the
"compatible" case rather than adding only a single 0 byte. This
simplifies the devinfo code a a bit, and avoids mistakes in other places
of the code (not in current upstream, but we had one such mistake in the
SUSE kernel).

[mkp: applied by hand and added braces]

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Martin Wilck and committed by
Martin K. Petersen
81df022b ba69ead9

+7 -15
+7 -15
drivers/scsi/scsi_devinfo.c
··· 34 34 }; 35 35 36 36 37 - static const char spaces[] = " "; /* 16 of them */ 38 37 static blist_flags_t scsi_default_dev_flags; 39 38 static LIST_HEAD(scsi_dev_info_list); 40 39 static char scsi_dev_flags[256]; ··· 297 298 size_t from_length; 298 299 299 300 from_length = strlen(from); 300 - strncpy(to, from, min(to_length, from_length)); 301 - if (from_length < to_length) { 302 - if (compatible) { 303 - /* 304 - * NUL terminate the string if it is short. 305 - */ 306 - to[from_length] = '\0'; 307 - } else { 308 - /* 309 - * space pad the string if it is short. 310 - */ 311 - strncpy(&to[from_length], spaces, 312 - to_length - from_length); 313 - } 301 + /* This zero-pads the destination */ 302 + strncpy(to, from, to_length); 303 + if (from_length < to_length && !compatible) { 304 + /* 305 + * space pad the string if it is short. 306 + */ 307 + memset(&to[from_length], ' ', to_length - from_length); 314 308 } 315 309 if (from_length > to_length) 316 310 printk(KERN_WARNING "%s: %s string '%s' is too long\n",