From: Kamalesh Babulal Date: Thu, 2 Jun 2022 16:04:32 +0000 (-0600) Subject: api.c: search_and_append_mnt_path() use strncpy() X-Git-Tag: v3.0~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa6d6301581f86759291b65704e91a31cb100cb4;p=thirdparty%2Flibcgroup.git api.c: search_and_append_mnt_path() use strncpy() Fix copy into fixed size buffer warning, reported by Coverity tool: CID 258279 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW). fixed_size_dest: You might overrun the 4096-character fixed-size string mnt_point->path by copying path without checking the length. 10. parameter_as_source: Note: This defect has an elevated risk because the source argument is a parameter of the current function. fix this issue by using strnpy(), in place of strcpy(). Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index d0e73410..ab5c8ef0 100644 --- a/src/api.c +++ b/src/api.c @@ -6085,7 +6085,9 @@ static int search_and_append_mnt_path(struct cg_mount_point **mount_point, return ECGOTHER; } - strcpy(mnt_point->path, path); + strncpy(mnt_point->path, path, FILENAME_MAX - 1); + mnt_point->path[FILENAME_MAX - 1] = '\0'; + mnt_point->next = NULL; if (*mount_point == NULL)