commit: caeab9d0ed9faa52213ce83a06e2ba2e988b9ac3
parent 66f1350798f6c3b5edce175fc98c9b81e3e345cb
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 23 Oct 2025 01:47:45 +0200
Replace strncpy with lib_strlcpy
This way NULL-termination is guaranteed.
Diffstat:
4 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/cmd/install.c b/cmd/install.c
@@ -10,6 +10,7 @@
#include "../libutils/fs.h"
#include "../libutils/getopt_nolong.h"
#include "../libutils/lib_mkdir.h"
+#include "../libutils/lib_string.h"
#include "../libutils/mode.h"
#include "../libutils/user_group_parse.h"
@@ -348,7 +349,7 @@ main(int argc, char *argv[])
char path_dup[PATH_MAX] = "";
if(!multi_src)
{
- strncpy(path_dup, dest, PATH_MAX);
+ lib_strlcpy(path_dup, dest, PATH_MAX);
destdir = dirname(path_dup);
}
diff --git a/cmd/mktemp.c b/cmd/mktemp.c
@@ -6,6 +6,7 @@
#define _DEFAULT_SOURCE // getentropy
#include "../config.h" // HAS_*
#include "../libutils/getopt_nolong.h"
+#include "../libutils/lib_string.h"
#include <errno.h>
#include <limits.h> // PATH_MAX
@@ -132,7 +133,7 @@ main(int argc, char *argv[])
if(argc == 1)
{
- strncpy(template, *argv, PATH_MAX);
+ lib_strlcpy(template, *argv, PATH_MAX);
}
else if(argc > 1)
{
diff --git a/cmd/mv.c b/cmd/mv.c
@@ -15,6 +15,7 @@
#include "../libutils/consent.h"
#include "../libutils/fs.h"
#include "../libutils/getopt_nolong.h"
+#include "../libutils/lib_string.h"
#include <dirent.h> // fdopendir
#include <errno.h>
@@ -545,8 +546,8 @@ main(int argc, char *argv[])
for(int i = 0; i < argc; i++)
{
- char arg[PATH_MAX] = "";
- strcpy(arg, argv[i]);
+ static char arg[PATH_MAX] = "";
+ lib_strlcpy(arg, argv[i], PATH_MAX);
char *filename = basename(arg);
diff --git a/libutils/lib_mkdir.c b/libutils/lib_mkdir.c
@@ -6,6 +6,8 @@
#include "./lib_mkdir.h"
+#include "./lib_string.h"
+
#include <errno.h>
#include <limits.h> // PATH_MAX
#include <stdio.h> // fprintf
@@ -23,7 +25,7 @@ mkdir_parents(char *path, mode_t mode)
}
char parent[PATH_MAX] = "";
- strncpy(parent, path, PATH_MAX);
+ lib_strlcpy(parent, path, PATH_MAX);
for(int i = strlen(parent) - 1; i >= 0; i--)
{