From 7f76bc8a7557aa835667566aef9c8a2a8b18c2bb Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 3 Oct 2018 17:08:11 +0200 Subject: su: cleanup code to copy to log strings man utmp: String fields are terminated by a null byte ('\0') if they are shorter than the size of the field. Signed-off-by: Karel Zak --- login-utils/su-common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'login-utils') diff --git a/login-utils/su-common.c b/login-utils/su-common.c index 1b1370922..e0604e246 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -609,14 +609,14 @@ static void log_btmp(struct su_context *su) DBG(LOG, ul_debug("btmp logging")); memset(&ut, 0, sizeof(ut)); - strncpy(ut.ut_user, + str2memcpy(ut.ut_user, su->pwd && su->pwd->pw_name ? su->pwd->pw_name : "(unknown)", sizeof(ut.ut_user)); if (su->tty_number) - xstrncpy(ut.ut_id, su->tty_number, sizeof(ut.ut_id)); + str2memcpy(ut.ut_id, su->tty_number, sizeof(ut.ut_id)); if (su->tty_name) - xstrncpy(ut.ut_line, su->tty_name, sizeof(ut.ut_line)); + str2memcpy(ut.ut_line, su->tty_name, sizeof(ut.ut_line)); gettimeofday(&tv, NULL); ut.ut_tv.tv_sec = tv.tv_sec; -- cgit v1.2.3-55-g7522