Skip to contentSkip to conversation

scsi_id: prevent buffer overflow in check_fill_0x83_prespc3()

PATCH Applied Harald Hoyer 2 participants 3 messages Sep 16, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi_id: prevent buffer overflow in check_fill_0x83_prespc3()

see https://bugzilla.redhat.com/show_bug.cgi?idQ6920

---
 extras/scsi_id/scsi_serial.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
extras/scsi_id/scsi_serial.c +1 -1
index 9235912..c456507 100644
@@ -582,7 +582,7 @@ static int check_fill_0x83_prespc3(struct udev *udev,
 		serial[j++] = hex_str[(page_83[4+i] & 0xf0) >> 4];
 		serial[j++] = hex_str[ page_83[4+i] & 0x0f];
 	}
-	strcpy(serial_short, serial);
+	strncpy(serial_short, serial, max_len-1);
 	return 0;
 }
 
Signature · 1 line
1.6.2.5
#1 lore raw

PATCH 1/1 scsi_id: prevent buffer overflow in check_fill_0x83_prespc3()

see https://bugzilla.redhat.com/show_bug.cgi?idQ6920

---
 extras/scsi_id/scsi_serial.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
extras/scsi_id/scsi_serial.c +3 -2
index 9235912..ab0ffd6 100644
@@ -578,11 +578,12 @@ static int check_fill_0x83_prespc3(struct udev *udev,
 	/* serial has been memset to zero before */
 	j = strlen(serial);	/* j = 1; */
 
-	for (i = 0; i < page_83[3]; ++i) {
+	for (i = 0; (i < page_83[3]) && (j < max_len-3); ++i) {
 		serial[j++] = hex_str[(page_83[4+i] & 0xf0) >> 4];
 		serial[j++] = hex_str[ page_83[4+i] & 0x0f];
 	}
-	strcpy(serial_short, serial);
+	serial[max_len-1] = 0;
+	strncpy(serial_short, serial, max_len-1);
 	return 0;
 }
 
Signature · 1 line
1.6.2.5