From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.windriver.com (mail.windriver.com [147.11.1.11]) by dpdk.org (Postfix) with ESMTP id 55FD5324B for ; Thu, 16 Aug 2018 12:04:08 +0200 (CEST) Received: from ala-blade48.wrs.com (ala-blade48.wrs.com [147.11.105.68]) by mail.windriver.com (8.15.2/8.15.1) with SMTP id w7GA46Q8019285 for ; Thu, 16 Aug 2018 03:04:06 -0700 (PDT) Received: by ala-blade48.wrs.com (sSMTP sendmail emulation); Thu, 16 Aug 2018 03:04:05 -0700 From: He Zhe To: stable@dpdk.org Date: Thu, 16 Aug 2018 03:04:05 -0700 Message-Id: <20180816100405.37777-1-zhe.he@windriver.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-stable] [PATCH] dpdk 17.11: Fix strncpy error for GCC8 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Aug 2018 10:04:08 -0000 GCC 8 adds -Wstringop-truncation. If -Werror=stringop-truncation is enabled. We will meet errors like the following: examples/vhost_scsi/scsi.c:213:4: error: 'strncpy' output may be truncated copying 32 bytes from a string of length 63 [-Werror=stringop-truncation] | strncpy((char *)vpage->params, bdev->name, 32); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: He Zhe --- examples/ip_pipeline/config_parse_tm.c | 2 +- examples/ipsec-secgw/parser.c | 2 +- examples/vhost_scsi/scsi.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/ip_pipeline/config_parse_tm.c b/examples/ip_pipeline/config_parse_tm.c index e75eed71f..1c945c9cd 100644 --- a/examples/ip_pipeline/config_parse_tm.c +++ b/examples/ip_pipeline/config_parse_tm.c @@ -352,7 +352,7 @@ tm_cfgfile_load_sched_subport( char name[CFG_NAME_LEN + 1]; profile = atoi(entries[j].value); - strncpy(name, + memcpy(name, entries[j].name, sizeof(name)); n_tokens = rte_strsplit( diff --git a/examples/ipsec-secgw/parser.c b/examples/ipsec-secgw/parser.c index 9d0ea4626..e0881b744 100644 --- a/examples/ipsec-secgw/parser.c +++ b/examples/ipsec-secgw/parser.c @@ -544,7 +544,7 @@ parse_cfg_file(const char *cfg_filename) goto error_exit; } - strncpy(str + strlen(str), oneline, + memcpy(str + strlen(str), oneline, strlen(oneline)); continue; diff --git a/examples/vhost_scsi/scsi.c b/examples/vhost_scsi/scsi.c index fd430ec23..47c5c83cf 100644 --- a/examples/vhost_scsi/scsi.c +++ b/examples/vhost_scsi/scsi.c @@ -210,7 +210,7 @@ vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev, break; case SPC_VPD_UNIT_SERIAL_NUMBER: hlen = 4; - strncpy((char *)vpage->params, bdev->name, 32); + memcpy((char *)vpage->params, bdev->name, 32); vpage->alloc_len = rte_cpu_to_be_16(32); break; case SPC_VPD_DEVICE_IDENTIFICATION: @@ -247,7 +247,7 @@ vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev, strncpy((char *)desig->desig, "INTEL", 8); vhost_strcpy_pad((char *)&desig->desig[8], bdev->product_name, 16, ' '); - strncpy((char *)&desig->desig[24], bdev->name, 32); + memcpy((char *)&desig->desig[24], bdev->name, 32); len += sizeof(struct scsi_desig_desc) + 8 + 16 + 32; buf += sizeof(struct scsi_desig_desc) + desig->len; @@ -312,7 +312,7 @@ vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev, bdev->product_name); /* PRODUCT REVISION LEVEL */ - strncpy((char *)inqdata->product_rev, "0001", 4); + memcpy((char *)inqdata->product_rev, "0001", 4); /* Standard inquiry data ends here. Only populate * remaining fields if alloc_len indicates enough -- 2.11.0