From cdb48431641428f06c2481739af095a55cd79cdb Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Tue, 26 Nov 2024 16:56:05 +1100 Subject: [PATCH] fix(tests): fix UB in mk{fifo,nod,nodat} Memory chunk is allocated with `malloc` and used as the `dest` buffer for `strncat`. The `dest` argument in `strncat` has to be NUL terminated, however it was not. This commit fixes this issue in mk{fifo,nod,noat}.c. Almost all dynamic tests pass now. Signed-off-by: Anhad Singh --- tests/mkfifo.c | 2 ++ tests/mknod.c | 2 ++ tests/mknodat.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/mkfifo.c b/tests/mkfifo.c index ad4dec2a9c..318419a507 100644 --- a/tests/mkfifo.c +++ b/tests/mkfifo.c @@ -11,7 +11,9 @@ int main(void) { char temp[] = "/tmp/stattest-XXXXXX"; const char file[] = "/mkfifo_fifo"; int len = sizeof(temp) + sizeof(file); + char* path = malloc(len * sizeof(char)); + path[0] = '\0'; if (path == NULL) { fprintf(stderr, "Could not allocate: %s\n", strerror(errno)); diff --git a/tests/mknod.c b/tests/mknod.c index 58e279f688..50d533a2a2 100644 --- a/tests/mknod.c +++ b/tests/mknod.c @@ -11,7 +11,9 @@ int main(void) { char temp[] = "/tmp/stattest-XXXXXX"; const char file[] = "/mknod"; int len = sizeof(temp) + sizeof(file); + char* path = malloc(len * sizeof(char)); + path[0] = '\0'; if (path == NULL) { fprintf(stderr, "Could not allocate: %s\n", strerror(errno)); diff --git a/tests/mknodat.c b/tests/mknodat.c index b449a30d5b..ad2798624f 100644 --- a/tests/mknodat.c +++ b/tests/mknodat.c @@ -12,7 +12,9 @@ int main(void) { const char separator[] = "/"; const char file[] = "mknod"; // relative int len = sizeof(temp) + sizeof(file) + sizeof(separator); + char* path = malloc(len * sizeof(char)); + path[0] = '\0'; if (path == NULL) { fprintf(stderr, "Could not allocate: %s\n", strerror(errno));