From f87f470415ad4e257f8ed8d8e2673baf5b9dbecb Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Sun, 13 Apr 2025 13:25:25 +0200 Subject: [PATCH] Fix pattern matching memory corruption --- src/configfile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/configfile.c b/src/configfile.c index 7b21bc7..6330151 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -428,12 +428,13 @@ static char *match_and_replace(const char *str, const char *pattern, char *devic assert(pattern != NULL); assert(device != NULL); - char *string = strndup(device, PATH_MAX); + char *string = calloc(PATH_MAX, 1); if (string == NULL) { tio_debug_printf("Failure allocating string memory\n"); return NULL; } + strncpy(string, device, PATH_MAX - 1); /* Find matches of pattern in str. For each match, replace any '%mN' in the * copy of the device string with the corresponding match subexpression and