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 <alx@kernel.org>
This commit is contained in:
Alejandro Colomar 2025-07-17 00:55:23 +02:00 committed by Serge Hallyn
parent ceaca8460f
commit e562faf109
2 changed files with 3 additions and 9 deletions

View File

@ -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

View File

@ -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;