diff mbox series

[3/4] fstests: t_getcwd.c, fix a warning related to buffer overflow

Message ID 7c1a98e17fdd0248c7d68302c28bd910883274ab.1674870429.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series fstest: fix compilation warnings | expand

Commit Message

Anand Jain Jan. 29, 2023, 2:42 a.m. UTC
GCC reports warning related to 'strncpy' and its specified bound being
equal to the destination buffer size.

t_getcwd.c: In function 'do_rename':
t_getcwd.c:40:2: warning: 'strncpy' specified bound 256 equals destination size [-Wstringop-truncation]
  strncpy(c_name, prefix, BUF_SIZE);

A buffer overflow is unlikely here because the only caller for
do_rename() sends a 16 char long %prefix and BUF_SIZE is defined as 256.

The change is made to reduce the buffer length in order to silence
compilation warning.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
 src/t_getcwd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series


diff --git a/src/t_getcwd.c b/src/t_getcwd.c
index 27255bd024e1..e9b5d7feb31f 100644
--- a/src/t_getcwd.c
+++ b/src/t_getcwd.c
@@ -30,14 +30,14 @@  int test_getcwd(char *init_cwd)
 	return 0;
-void do_rename(char *prefix)
+static void do_rename(char *prefix)
 	int i = 0;
 	int fd;
 	char c_name[BUF_SIZE];
 	char n_name[BUF_SIZE];
-	strncpy(c_name, prefix, BUF_SIZE);
+	strncpy(c_name, prefix, BUF_SIZE - 1);
 	fd = open(c_name, O_CREAT | O_RDWR, 0644);
 	if (fd < 0) {