diff mbox series

[4/4] fstests: aiodio_sparse2.c, fix compiler warning buffer overflow

Message ID 54868fe929ac17553747e0eb941192c85b4fe172.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
The warning is due to 'strncpy' with a maximum number of characters
equal to the destination buffer size, without space for null termination.

aiodio_sparse2.c: In function 'main':
aiodio_sparse2.c:404:9: warning: 'strncpy' specified bound 4096 equals destination size [-Wstringop-truncation]
  404 |         strncpy(filename, argv[argc-1], PATH_MAX);

However, PATH_MAX is including null termination at the end. Anyways, fix
warning by setting NULL.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 src/aio-dio-regress/aiodio_sparse2.c | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/src/aio-dio-regress/aiodio_sparse2.c b/src/aio-dio-regress/aiodio_sparse2.c
index 51ede5bb6c8b..685e3b9dce48 100644
--- a/src/aio-dio-regress/aiodio_sparse2.c
+++ b/src/aio-dio-regress/aiodio_sparse2.c
@@ -402,6 +402,7 @@  int main(int argc, char **argv)
 	}
 
 	strncpy(filename, argv[argc-1], PATH_MAX);
+	filename[PATH_MAX - 1] = '\0';
 
 	if (alignment == 0)
 		alignment = get_logical_block_size(filename);