commit: 125ed15d0a173242a77bebcc0fb322ac20f8248d
parent 084adeeaa12f457e7cfa6e38289ce0dc26827b88
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 1 Aug 2025 09:08:34 +0200
cmd/shuf: make sure lines are NULL-terminated
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/cmd/shuf.c b/cmd/shuf.c
@@ -51,7 +51,7 @@ shuf(FILE *in, const char *fname)
if(nread <= 0) return 0;
errno = 0;
- char *dup = malloc(nread);
+ char *dup = malloc(nread + 1);
if(!dup)
{
fprintf(
@@ -65,6 +65,7 @@ shuf(FILE *in, const char *fname)
return 1;
}
memcpy(dup, line, nread);
+ dup[nread] = '\0';
int p = rand() % LINES_LEN;
if(lines[p] != NULL)