From: Alejandro Colomar Date: Wed, 16 Jul 2025 22:55:23 +0000 (+0200) Subject: lib/: Use simple assignment instead of memcpy(3) X-Git-Tag: 4.19.0-rc1~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e562faf109422e2108db2fec4770d8f9da13db03;p=thirdparty%2Fshadow.git 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 --- diff --git a/lib/readpassphrase.c b/lib/readpassphrase.c index e23960f01..7deab5a61 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 41746c033..8ed9528f9 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;