From e562faf109422e2108db2fec4770d8f9da13db03 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Thu, 17 Jul 2025 00:55:23 +0200 Subject: [PATCH] lib/: Use simple assignment instead of memcpy(3) memcpy(3) is overkill, and much more dangerous than simple assignment. Simple assignment adds type safety, and removes any possibility of buffer overflow due to accidentally specifying a wrong size. Signed-off-by: Alejandro Colomar --- lib/readpassphrase.c | 2 +- lib/utmp.c | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/readpassphrase.c b/lib/readpassphrase.c index e23960f0..7deab5a6 100644 --- a/lib/readpassphrase.c +++ b/lib/readpassphrase.c @@ -91,7 +91,7 @@ restart: * generate SIGTTOU, so do it *before* installing the signal handlers. */ if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) { - memcpy(&term, &oterm, sizeof(term)); + term = oterm; if (!(flags & RPP_ECHO_ON)) term.c_lflag &= ~(ECHO | ECHONL); #ifdef VSTATUS diff --git a/lib/utmp.c b/lib/utmp.c index 41746c03..8ed9528f 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -318,16 +318,10 @@ prepare_utmp(const char *name, const char *line, const char *host, struct sockaddr_in *sa = (struct sockaddr_in *) info->ai_addr; # if defined(HAVE_STRUCT_UTMPX_UT_ADDR) - memcpy (&(utent->ut_addr), - &(sa->sin_addr), - MIN(sizeof(utent->ut_addr), - sizeof(sa->sin_addr))); + utent->ut_addr = sa->sin_addr.s_addr; # endif # if defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6) - memcpy (utent->ut_addr_v6, - &(sa->sin_addr), - MIN(sizeof(utent->ut_addr_v6), - sizeof(sa->sin_addr))); + utent->ut_addr_v6[0] = sa->sin_addr.s_addr; } else if (info->ai_family == AF_INET6) { struct sockaddr_in6 *sa = (struct sockaddr_in6 *) info->ai_addr;