diff options
author | Sami Kerola | 2016-05-07 01:20:32 +0200 |
---|---|---|
committer | Sami Kerola | 2016-07-01 21:59:23 +0200 |
commit | e4aaa0e5932e12671d209a5fcf60f4775b7820a8 (patch) | |
tree | fdb8de1be2d4a688258e10c29b655a7e2f779745 /term-utils | |
parent | write: set atime value in term_chk() only when needed (diff) | |
download | kernel-qcow2-util-linux-e4aaa0e5932e12671d209a5fcf60f4775b7820a8.tar.gz kernel-qcow2-util-linux-e4aaa0e5932e12671d209a5fcf60f4775b7820a8.tar.xz kernel-qcow2-util-linux-e4aaa0e5932e12671d209a5fcf60f4775b7820a8.zip |
write: use xstrncpy() from strutils.h
Earlier if the tty path was exactly length of the maximum ut_line then last
character of the path was overwrote by \0. This is in practise theoretical
bug, as it is unheard that a tty device path could be 32 characters long.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils')
-rw-r--r-- | term-utils/write.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/term-utils/write.c b/term-utils/write.c index fb9cdf59b..11a658041 100644 --- a/term-utils/write.c +++ b/term-utils/write.c @@ -63,6 +63,7 @@ #include "carefulputc.h" #include "closestream.h" #include "nls.h" +#include "strutils.h" #include "xalloc.h" static void __attribute__ ((__noreturn__)) usage(FILE * out) @@ -164,8 +165,7 @@ static void search_utmp(char *user, char *tty, char *mytty, uid_t myuid) memcpy(&u, uptr, sizeof(u)); if (strncmp(user, u.ut_user, sizeof(u.ut_user)) == 0) { ++nloggedttys; - strncpy(atty, u.ut_line, sizeof(u.ut_line)); - atty[sizeof(u.ut_line)] = '\0'; + xstrncpy(atty, u.ut_line, sizeof(atty)); if (term_chk(atty, &msgsok, &atime, 0)) /* bad term? skip */ continue; |