From f5acfbab44d45d1231c08a3774c8c5cafdf72925 Mon Sep 17 00:00:00 2001 From: Gautham Date: Fri, 27 Dec 2024 22:23:39 -0600 Subject: [PATCH] free replacement string replacement string needs one more byte also --- tool/build/renamestr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tool/build/renamestr.c b/tool/build/renamestr.c index 3e835627a..328408075 100644 --- a/tool/build/renamestr.c +++ b/tool/build/renamestr.c @@ -404,16 +404,17 @@ static void OpenInput(const char *path) { static void ReplaceString(struct Param *param) { Elf64_Xword len = strnlen(param->roloc, roend - param->roloc); - char *targstr = Malloc(len); - for (Elf64_Xword i = 0; i < len; ++i) + char *targstr = Malloc(len + 1); + for (Elf64_Xword i = 0; i < len + 1; ++i) targstr[i] = 0; - strcat(targstr, param->to_string); + strcpy(targstr, param->to_string); strcat(targstr, param->roloc + param->from_len); #ifdef MODE_DBG kprintf("'%s' should be '%s'\n", param->roloc, targstr); #endif strcpy(param->roloc, targstr); param->roloc += len; + free(targstr); } int main(int argc, char *argv[]) {