]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
su: cleanup code to copy to log strings
authorKarel Zak <kzak@redhat.com>
Wed, 3 Oct 2018 15:08:11 +0000 (17:08 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 3 Oct 2018 15:10:13 +0000 (17:10 +0200)
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 <kzak@redhat.com>
login-utils/su-common.c

index 1b1370922c9816709ec2d93905b15c35c051cea9..e0604e246d8f4a7ca72415ee2275b602f08f2d27 100644 (file)
@@ -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;