login: use mem2strcpy() rather than rely on printf()
The strings from utmp does not have to be terminated. It's seems better to explicitly terminate it than rely on "%.*s" printf() functionality -- printf() man page assumes that "If a precision is given, no null byte need be present", but static analyzers are pretty unhappy with it. Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
3cb827ad36
commit
b648917e0b
|
@ -597,17 +597,20 @@ static void log_lastlog(struct login_context *cxt)
|
||||||
if ((pread(fd, (void *)&ll, sizeof(ll), offset) == sizeof(ll)) &&
|
if ((pread(fd, (void *)&ll, sizeof(ll), offset) == sizeof(ll)) &&
|
||||||
ll.ll_time != 0) {
|
ll.ll_time != 0) {
|
||||||
char time_string[CTIME_BUFSIZ];
|
char time_string[CTIME_BUFSIZ];
|
||||||
|
char buf[sizeof(ll.ll_host) + 1];
|
||||||
|
|
||||||
time_t ll_time = (time_t) ll.ll_time;
|
time_t ll_time = (time_t) ll.ll_time;
|
||||||
|
|
||||||
ctime_r(&ll_time, time_string);
|
ctime_r(&ll_time, time_string);
|
||||||
printf(_("Last login: %.*s "), 24 - 5, time_string);
|
printf(_("Last login: %.*s "), 24 - 5, time_string);
|
||||||
if (*ll.ll_host != '\0')
|
|
||||||
printf(_("from %.*s\n"),
|
if (*ll.ll_host != '\0') {
|
||||||
(int)sizeof(ll.ll_host), ll.ll_host);
|
mem2strcpy(buf, ll.ll_host, sizeof(ll.ll_host), sizeof(buf));
|
||||||
else
|
printf(_("from %s\n"), buf);
|
||||||
printf(_("on %.*s\n"),
|
} else {
|
||||||
(int)sizeof(ll.ll_line), ll.ll_line);
|
mem2strcpy(buf, ll.ll_line, sizeof(ll.ll_line), sizeof(buf));
|
||||||
|
printf(_("on %s\n"), buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue