diff options
author | Alejandro Colomar <alx@kernel.org> | 2023-11-15 22:36:19 +0100 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-11-16 15:26:45 +0100 |
commit | a67af5f8609185b88dc56c546648f24c1b55fdf2 (patch) | |
tree | 352945696f290da35ab7c9576c7f53074f3228d6 | |
parent | fb3cf24b56f3d6c14a566161dc40a29e5406b41c (diff) |
lib/: Use STRNCPY() instead of strncpy(3)
We've recently fixed several bugs in the calculation of the size in this
function call. Use this wrapper to prevent similar mistakes in the
future.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | lib/log.c | 3 | ||||
-rw-r--r-- | lib/utmp.c | 13 |
2 files changed, 9 insertions, 7 deletions
@@ -19,6 +19,7 @@ #include <lastlog.h> #include "memzero.h" #include "prototypes.h" +#include "strncpy.h" #include "strtcpy.h" @@ -82,7 +83,7 @@ void dolastlog ( newlog.ll_time = ll_time; STRTCPY(newlog.ll_line, line); #if HAVE_LL_HOST - strncpy(newlog.ll_host, host, sizeof(newlog.ll_host)); + STRNCPY(newlog.ll_host, host); #endif if ( (lseek (fd, offset, SEEK_SET) != offset) || (write_full(fd, &newlog, sizeof newlog) == -1) @@ -25,6 +25,7 @@ #include "alloc.h" #include "sizeof.h" #include "strtcpy.h" +#include "strncpy.h" #include "zustr2stp.h" #ident "$Id$" @@ -262,25 +263,25 @@ static utent->ut_type = USER_PROCESS; #endif /* HAVE_STRUCT_UTMP_UT_TYPE */ utent->ut_pid = getpid (); - strncpy(utent->ut_line, line, sizeof(utent->ut_line)); + STRNCPY(utent->ut_line, line); #ifdef HAVE_STRUCT_UTMP_UT_ID if (NULL != ut) { - strncpy (utent->ut_id, ut->ut_id, sizeof (utent->ut_id)); + STRNCPY(utent->ut_id, ut->ut_id); } else { /* XXX - assumes /dev/tty?? */ - strncpy(utent->ut_id, line + 3, sizeof(utent->ut_id)); + STRNCPY(utent->ut_id, line + 3); } #endif /* HAVE_STRUCT_UTMP_UT_ID */ #ifdef HAVE_STRUCT_UTMP_UT_NAME - strncpy (utent->ut_name, name, sizeof (utent->ut_name)); + STRNCPY(utent->ut_name, name); #endif /* HAVE_STRUCT_UTMP_UT_NAME */ #ifdef HAVE_STRUCT_UTMP_UT_USER - strncpy(utent->ut_user, name, sizeof(utent->ut_user)); + STRNCPY(utent->ut_user, name); #endif /* HAVE_STRUCT_UTMP_UT_USER */ if (NULL != hostname) { struct addrinfo *info = NULL; #ifdef HAVE_STRUCT_UTMP_UT_HOST - strncpy(utent->ut_host, hostname, sizeof(utent->ut_host)); + STRNCPY(utent->ut_host, hostname); #endif /* HAVE_STRUCT_UTMP_UT_HOST */ #ifdef HAVE_STRUCT_UTMP_UT_SYSLEN utent->ut_syslen = MIN (strlen (hostname), |