Skip to contentSkip to conversation

target: change sprintf to snprintf

PATCH Applied Dan Carpenter 2 participants 3 messages Jan 18, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: change sprintf to snprintf

"buf" is 128 characters and "vpd->device_identifier" is 256. It makes the static checkers complain.

---
Probably we should just raise VPD_TMP_BUF_SIZE to 300.

drivers/target/target_core_transport.c +6 -3
index bd587b7..96b64d5 100644
@@ -907,15 +907,18 @@ int transport_dump_vpd_ident(
 
 	switch (vpd->device_identifier_code_set) {
 	case 0x01: /* Binary */
-		sprintf(buf, "T10 VPD Binary Device Identifier: %s\n",
+		snprintf(buf, sizeof(buf),
+			"T10 VPD Binary Device Identifier: %s\n",
 			&vpd->device_identifier[0]);
 		break;
 	case 0x02: /* ASCII */
-		sprintf(buf, "T10 VPD ASCII Device Identifier: %s\n",
+		snprintf(buf, sizeof(buf),
+			"T10 VPD ASCII Device Identifier: %s\n",
 			&vpd->device_identifier[0]);
 		break;
 	case 0x03: /* UTF-8 */
-		sprintf(buf, "T10 VPD UTF-8 Device Identifier: %s\n",
+		snprintf(buf, sizeof(buf),
+			"T10 VPD UTF-8 Device Identifier: %s\n",
 			&vpd->device_identifier[0]);
 		break;
 	default:
#1 lore raw
Quoted 5 lines · Dan Carpenter

"buf" is 128 characters and "vpd->device_identifier" is 256. It makes the static checkers complain.

---

Applied to target-pending/for-next.

Quoted 1 line

Probably we should just raise VPD_TMP_BUF_SIZE to 300.

Also bumping up VPD_TMP_BUF_SIZE to 254 to match the usage with INQUIRY_VPD_DEVICE_IDENTIFIER_LEN sized vpd->device_identifier[] below.

Thanks Dan!

--nab

Quoted 27 lines
drivers/target/target_core_transport.c +6 -3
index bd587b7..96b64d5 100644
@@ -907,15 +907,18 @@ int transport_dump_vpd_ident(
 
 	switch (vpd->device_identifier_code_set) {
 	case 0x01: /* Binary */
-		sprintf(buf, "T10 VPD Binary Device Identifier: %s\n",
+		snprintf(buf, sizeof(buf),
+			"T10 VPD Binary Device Identifier: %s\n",
 			&vpd->device_identifier[0]);
 		break;
 	case 0x02: /* ASCII */
-		sprintf(buf, "T10 VPD ASCII Device Identifier: %s\n",
+		snprintf(buf, sizeof(buf),
+			"T10 VPD ASCII Device Identifier: %s\n",
 			&vpd->device_identifier[0]);
 		break;
 	case 0x03: /* UTF-8 */
-		sprintf(buf, "T10 VPD UTF-8 Device Identifier: %s\n",
+		snprintf(buf, sizeof(buf),
+			"T10 VPD UTF-8 Device Identifier: %s\n",
 			&vpd->device_identifier[0]);
 		break;
 	default:
#2 lore raw
Quoted 7 lines · Nicholas A. Bellinger
Quoted 5 lines · Dan Carpenter

"buf" is 128 characters and "vpd->device_identifier" is 256. It makes the static checkers complain.

---

Quoted 7 lines

Applied to target-pending/for-next.

Quoted 1 line

Probably we should just raise VPD_TMP_BUF_SIZE to 300.

Also bumping up VPD_TMP_BUF_SIZE to 254 to match the usage with INQUIRY_VPD_DEVICE_IDENTIFIER_LEN sized vpd->device_identifier[] below.

It could still go over 254 because it's "T10 VPD Binary Device
Identifier: " plus INQUIRY_VPD_DEVICE_IDENTIFIER_LEN. But I agree that probably 254 is enough space.

regards,
dan carpenter