Browse Source

HDFS-15922. Use memcpy for copying non-null terminated string in jni_helper.c (#2818)

Gautham B A 4 years ago
parent
commit
1fed18bb2d

+ 3 - 3
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c

@@ -422,9 +422,9 @@ static ssize_t wildcard_expandPath(const char* path, char* expanded)
 
 
                 if (expanded != NULL) {
                 if (expanded != NULL) {
                     // pathLength includes an extra '.'
                     // pathLength includes an extra '.'
-                    strncpy(dest, path, pathLength-1);
+                    memcpy(dest, path, pathLength - 1);
                     dest += pathLength - 1;
                     dest += pathLength - 1;
-                    strncpy(dest, filename, filenameLength);
+                    memcpy(dest, filename, filenameLength);
                     dest += filenameLength;
                     dest += filenameLength;
                     *dest = PATH_SEPARATOR;
                     *dest = PATH_SEPARATOR;
                     dest++;
                     dest++;
@@ -536,7 +536,7 @@ static ssize_t getClassPath_helper(const char *classpath, char* expandedClasspat
             // +1 for path separator or null terminator
             // +1 for path separator or null terminator
             length += tokenlen + 1;
             length += tokenlen + 1;
             if (expandedCP_curr != NULL) {
             if (expandedCP_curr != NULL) {
-                strncpy(expandedCP_curr, cp_token, tokenlen);
+                memcpy(expandedCP_curr, cp_token, tokenlen);
                 expandedCP_curr += tokenlen;
                 expandedCP_curr += tokenlen;
                 *expandedCP_curr = PATH_SEPARATOR;
                 *expandedCP_curr = PATH_SEPARATOR;
                 expandedCP_curr++;
                 expandedCP_curr++;