From 7b4bc2a2438aa035dd495007b23edab638b409fc Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 30 Mar 2018 14:37:40 -0700 Subject: [PATCH] nvme/identify: print ASCII strings with helper SN, MN, and FR are ASCII strings as defined by the NVMe spec; use the new print_ascii_string() helper function to print them. This trims the trailing spaces and prevents accidentally printing any control characters to the screen if the device provides an invalid ASCII string. Change-Id: Ifaf383a79e13be62625250e7e79a305ebaa3612b Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/405926 Tested-by: SPDK Automated Test System Reviewed-by: Changpeng Liu Reviewed-by: Ben Walker --- examples/nvme/identify/identify.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index c5fe32e56..297faf313 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -643,12 +643,15 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport printf("================================\n"); printf("Vendor ID: %04x\n", cdata->vid); printf("Subsystem Vendor ID: %04x\n", cdata->ssvid); - snprintf(str, sizeof(cdata->sn) + 1, "%s", cdata->sn); - printf("Serial Number: %s\n", str); - snprintf(str, sizeof(cdata->mn) + 1, "%s", cdata->mn); - printf("Model Number: %s\n", str); - snprintf(str, sizeof(cdata->fr) + 1, "%s", cdata->fr); - printf("Firmware Version: %s\n", str); + printf("Serial Number: "); + print_ascii_string(cdata->sn, sizeof(cdata->sn)); + printf("\n"); + printf("Model Number: "); + print_ascii_string(cdata->mn, sizeof(cdata->mn)); + printf("\n"); + printf("Firmware Version: "); + print_ascii_string(cdata->fr, sizeof(cdata->fr)); + printf("\n"); printf("Recommended Arb Burst: %d\n", cdata->rab); printf("IEEE OUI Identifier: %02x %02x %02x\n", cdata->ieee[0], cdata->ieee[1], cdata->ieee[2]);