aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-08-21 08:34:37 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-08-21 08:34:37 +0100
commite9eaba12d196e0b526fb24f549466ce76168634b (patch)
treed203e54961b8d0b0eb62f5834bc046a651dc1795
parent7853f637c03e43190c3c15af1b949e71fe915513 (diff)
downloadalisp-e9eaba12d196e0b526fb24f549466ce76168634b.tar.gz
alisp-e9eaba12d196e0b526fb24f549466ce76168634b.tar.bz2
alisp-e9eaba12d196e0b526fb24f549466ce76168634b.zip
Fix issues with buffer overflow when printing products of sv_copy
Happens because we have no null terminator on the string - rookie mistake.
-rw-r--r--main.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/main.c b/main.c
index bbd10e5..8223ada 100644
--- a/main.c
+++ b/main.c
@@ -20,8 +20,9 @@
sv_t sv_copy(sv_t old)
{
- char *newstr = calloc(1, old.size * sizeof(*newstr));
+ char *newstr = calloc(1, (old.size + 1) * sizeof(*newstr));
memcpy(newstr, old.data, old.size);
+ newstr[old.size] = '\0';
return SV(newstr, old.size);
}