]> git.kaiwu.me - njs.git/commitdiff
Improved njs_ftw().
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 23 Dec 2021 13:30:44 +0000 (13:30 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 23 Dec 2021 13:30:44 +0000 (13:30 +0000)
Replacing strcpy() with memcpy() as the former is considered
insecure.

Found by Clang static analyzer.

external/njs_fs.c

index e76ac1549e6ffc0896adcdfe7cf80688fd2843d9..d0cd4bf98b3b0415573a1050fca691dc70efab07 100644 (file)
@@ -2153,7 +2153,7 @@ njs_ftw(char *path, njs_file_tree_walk_cb_t cb, int fd_limit,
             }
 
             path[base] = '/';
-            strcpy(path + base + 1, d_name);
+            memcpy(&path[base + 1], d_name, length + sizeof("\0"));
 
             if (fd_limit != 0) {
                 ret = njs_ftw(path, cb, fd_limit - 1, flags, &trace);