Skip to content

Commit 116262f

Browse files
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 specifying a wrong size. Signed-off-by: Alejandro Colomar <[email protected]>
1 parent 90042ad commit 116262f

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

lib/readpassphrase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
9191
* generate SIGTTOU, so do it *before* installing the signal handlers.
9292
*/
9393
if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) {
94-
memcpy(&term, &oterm, sizeof(term));
94+
term = oterm;
9595
if (!(flags & RPP_ECHO_ON))
9696
term.c_lflag &= ~(ECHO | ECHONL);
9797
#ifdef VSTATUS

lib/utmp.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,10 @@ prepare_utmp(const char *name, const char *line, const char *host,
302302
struct sockaddr_in *sa =
303303
(struct sockaddr_in *) info->ai_addr;
304304
# if defined(HAVE_STRUCT_UTMPX_UT_ADDR)
305-
memcpy (&(utent->ut_addr),
306-
&(sa->sin_addr),
307-
MIN (sizeof (utent->ut_addr),
308-
sizeof (sa->sin_addr)));
305+
utent->ut_addr = sa->sin_addr.s_addr;
309306
# endif
310307
# if defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6)
311-
memcpy (utent->ut_addr_v6,
312-
&(sa->sin_addr),
313-
MIN (sizeof (utent->ut_addr_v6),
314-
sizeof (sa->sin_addr)));
308+
utent->ut_addr_v6[0] = sa->sin_addr.s_addr;
315309
} else if (info->ai_family == AF_INET6) {
316310
struct sockaddr_in6 *sa =
317311
(struct sockaddr_in6 *) info->ai_addr;

0 commit comments

Comments
 (0)