]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/: Use simple assignment instead of memcpy(3)
authorAlejandro Colomar <alx@kernel.org>
Wed, 16 Jul 2025 22:55:23 +0000 (00:55 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 28 Nov 2025 19:40:58 +0000 (13:40 -0600)
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>
lib/readpassphrase.c
lib/utmp.c

index e23960f0126b82a35ac603d2379e4fe56ee7c2f1..7deab5a6196e8595bd53ae5a16216a13d50232dc 100644 (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
index 41746c033907d40731967f13f813340042ee7020..8ed9528f9ca7daea8d48b6f9a51258dc23d59f82 100644 (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;