Skip to content

Commit e562faf

Browse files
alejandro-colomarhallyn
authored andcommitted
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 <[email protected]>
1 parent ceaca84 commit e562faf

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
@@ -318,16 +318,10 @@ prepare_utmp(const char *name, const char *line, const char *host,
318318
struct sockaddr_in *sa =
319319
(struct sockaddr_in *) info->ai_addr;
320320
# if defined(HAVE_STRUCT_UTMPX_UT_ADDR)
321-
memcpy (&(utent->ut_addr),
322-
&(sa->sin_addr),
323-
MIN(sizeof(utent->ut_addr),
324-
sizeof(sa->sin_addr)));
321+
utent->ut_addr = sa->sin_addr.s_addr;
325322
# endif
326323
# if defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6)
327-
memcpy (utent->ut_addr_v6,
328-
&(sa->sin_addr),
329-
MIN(sizeof(utent->ut_addr_v6),
330-
sizeof(sa->sin_addr)));
324+
utent->ut_addr_v6[0] = sa->sin_addr.s_addr;
331325
} else if (info->ai_family == AF_INET6) {
332326
struct sockaddr_in6 *sa =
333327
(struct sockaddr_in6 *) info->ai_addr;

0 commit comments

Comments
 (0)