From 011236f238743b451793792e3293ab2baba2c06e Mon Sep 17 00:00:00 2001 From: Jesse Millwood Date: Wed, 30 Oct 2024 14:27:26 -0400 Subject: [PATCH] Fix buffer overflow with strcpy --- libs/chapter12/reverse_string.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/chapter12/reverse_string.cpp b/libs/chapter12/reverse_string.cpp index c6dc7e1..aec0f1f 100644 --- a/libs/chapter12/reverse_string.cpp +++ b/libs/chapter12/reverse_string.cpp @@ -9,7 +9,7 @@ void reverse_str(char *str){ size_t len = strlen(str); - char *tmp = reinterpret_cast(malloc(len)); + char *tmp = reinterpret_cast(malloc(len + 1)); strcpy(tmp, str); for(unsigned int offset = 0; offset < len; ++offset){ str[offset] = tmp[len-offset-1];