From cebda7a478f9943f10b9a3388377c61a54957a87 Mon Sep 17 00:00:00 2001 From: Jian Yu Date: Wed, 9 Oct 2019 14:30:49 -0700 Subject: [PATCH] LU-12844 lnet: fix strncpy bound error MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch fixes the following error while using gcc 8: liblnetconfig.c: In function ‘lustre_lnet_parse_nids’: liblnetconfig.c:320:3: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] strncpy(entry, cur, len - 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ liblnetconfig.c:310:10: note: length computed here len = strlen(cur) + 1; ^~~~~~~~~~~ cc1: all warnings being treated as errors Change-Id: I2d5840fd58c7b7d27ef1b2aa12f1f187d30abbfd Signed-off-by: Jian Yu Reviewed-on: https://review.whamcloud.com/36417 Tested-by: jenkins Reviewed-by: Andreas Dilger Reviewed-by: Amir Shehata Tested-by: Maloo Reviewed-by: James Simmons --- lnet/utils/lnetconfig/liblnetconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index 23612c8..5a50b21 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -317,7 +317,7 @@ int lustre_lnet_parse_nids(char *nids, char **array, int size, finish = i > 0 ? i - 1: 0; goto failed; } - strncpy(entry, cur, len - 1); + memcpy(entry, cur, len - 1); entry[len] = '\0'; new_array[i] = entry; if (comma) { -- 1.8.3.1