mirror of
https://github.com/systemd/systemd.git
synced 2026-08-12 12:16:06 +00:00
scsi_id: use strscpy instead of strncpy for wwn fields
strncpy does not null-terminate the destination buffer if the source string is longer than the count parameter. Since wwn and wwn_vendor_extension are char[17] and we copy up to 16 bytes, there's a risk of missing null termination. Use strscpy which always null-terminates. CID#1469706 Follow-up for4e9fdfccbd(cherry picked from commit86fd0337c6) (cherry picked from commitbf5951ea7d)
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "scsi.h"
|
||||
#include "scsi_id.h"
|
||||
#include "string-util.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "time-util.h"
|
||||
|
||||
/*
|
||||
@@ -518,9 +519,9 @@ static int check_fill_0x83_id(struct scsi_id_device *dev_scsi,
|
||||
strcpy(serial_short, serial + s);
|
||||
|
||||
if (id_search->id_type == SCSI_ID_NAA && wwn != NULL) {
|
||||
strncpy(wwn, serial + s, 16);
|
||||
strscpy(wwn, 17, serial + s);
|
||||
if (wwn_vendor_extension)
|
||||
strncpy(wwn_vendor_extension, serial + s + 16, 16);
|
||||
strscpy(wwn_vendor_extension, 17, serial + s + 16);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user