From 6a3e1353164d2b4d8fa568abadf13af9adde500d Mon Sep 17 00:00:00 2001 From: Gautham B A Date: Mon, 29 Mar 2021 23:08:59 +0530 Subject: [PATCH] HDFS-15922. Use memcpy for copying non-null terminated string. (#2827) --- .../src/main/native/fuse-dfs/fuse_init.c | 2 +- .../src/main/native/libhdfs-tests/test_libhdfs_ops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/fuse-dfs/fuse_init.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/fuse-dfs/fuse_init.c index 4da6da0fa9..205a7f40fd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/fuse-dfs/fuse_init.c +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/fuse-dfs/fuse_init.c @@ -74,7 +74,7 @@ static void init_protectedpaths(dfs_context *dfs) } dfs->protectedpaths[j] = (char*)malloc(sizeof(char)*length+1); assert(dfs->protectedpaths[j]); - strncpy(dfs->protectedpaths[j], tmp, length); + memcpy(dfs->protectedpaths[j], tmp, length); dfs->protectedpaths[j][length] = '\0'; if (eos) { tmp = eos + 1; diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_ops.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_ops.c index 23fa2e5112..a3058bbe6e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_ops.c +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_ops.c @@ -58,7 +58,7 @@ void permission_disp(short permissions, char *rtr) { default: perm = "???"; } - strncpy(rtr, perm, 3); + memcpy(rtr, perm, 3); rtr+=3; } }