From ae70db6cde5be5abd3bbbb26bd9af6fe68cc4b6b Mon Sep 17 00:00:00 2001 From: Cheyenne Wills Date: Tue, 24 May 2022 20:14:36 -0600 Subject: [PATCH] vol: Use asprintf in _namei_examine_special MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC-12 is flagging an snprintf statement with a format truncation warning: namei_ops.c: In function ‘namei_ListAFSSubDirs’: namei_ops.c:2029:22: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size between 0 and 511 [-Werror=format-truncation=] Change code to use asprintf instead of snprintf. Return an error if a memory allocation fails. Change-Id: I1f617ab22dbec4c2497ec482115cd20c9af0ecfa Reviewed-on: https://gerrit.openafs.org/14955 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- src/vol/namei_ops.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index d2f94bb707..d77f33ff7c 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -2023,13 +2023,17 @@ _namei_examine_special(char * path1, * this like a normal file, we won't try to INC or DEC it. */ info.linkCount = 0; } else { - char path2[512]; + char *path2; /* Open this handle */ - snprintf(path2, sizeof(path2), - "%s" OS_DIRSEP "%s", path1, dname); + if (asprintf(&path2, "%s" OS_DIRSEP "%s", path1, dname) < 0) { + Log("_namei_examine_special: memory allocation failure\n"); + ret = -1; + goto error; + } linkHandle->fd_fd = OS_OPEN(path2, Testing ? O_RDONLY : O_RDWR, 0666); info.linkCount = namei_GetLinkCount(linkHandle, (Inode) 0, 1, 1, Testing); + free(path2); } if (!judgeFun ||