Skip to contentSkip to conversation

target: don't assume t10_wwn.vendor is null terminated

PATCH Superseded David Disseldorp 2 participants 3 messages Nov 19, 2018 – Nov 20, 2018 SCSI target

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 2/4 target: don't assume t10_wwn.vendor is null terminated

---
 drivers/target/target_core_stat.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/target/target_core_stat.c +9 -2
index f0db91ebd735..89f35167f036 100644
@@ -804,10 +804,17 @@ static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
 	if (dev) {
 		wwn = &dev->t10_wwn;
 		/* scsiTransportDevName */
-		ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
+		if (strlen(wwn->unit_serial)) {
+			ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
+				tpg->se_tpg_tfo->tpg_get_wwn(tpg),
+				wwn->unit_serial);
+		} else {
+			ret = snprintf(page, PAGE_SIZE, "%s+%."
+				__stringify(INQUIRY_VENDOR_IDENTIFIER_LEN)
+				"s\n",
 				tpg->se_tpg_tfo->tpg_get_wwn(tpg),
-				(strlen(wwn->unit_serial)) ? wwn->unit_serial :
 				wwn->vendor);
+		}
 	}
 	rcu_read_unlock();
 	return ret;
Signature · 1 line
2.13.7
#1 lore raw

This could use a little more explanation, the code doesn't just add a little if but also changes the existing case. Also where can't it be null currently?

#2 lore raw
In reply to David Disseldorp
Quoted 3 lines · Christoph Hellwig

This could use a little more explanation, the code doesn't just add a little if but also changes the existing case. Also where can't it be null currently?

I'll add an explanation in the next round. This patch shouldn't cause any change in behaviour. The vendor string is currently always NULL terminated, but won't be once patch 3/4 is applied, hence the need to add the maximum string width specifier.

Thanks for the feedback.