Make sure logintime string can never overflow (Coverity CID 1164485).

This commit is contained in:
Petter Reinholdtsen 2014-01-26 13:38:51 +00:00
parent ae7c73ec7f
commit 7d6e3683b0

View File

@ -396,7 +396,8 @@ int list(struct utmp *p, time_t t, int what)
* Calculate times * Calculate times
*/ */
tmp = (time_t)p->ut_time; tmp = (time_t)p->ut_time;
strcpy(logintime, ctime(&tmp)); strncpy(logintime, ctime(&tmp), sizeof(logintime));
logintime[sizeof(logintime)-1] = 0; /* enforce null termination */
if (fulltime) if (fulltime)
sprintf(logouttime, "- %s", ctime(&t)); sprintf(logouttime, "- %s", ctime(&t));
else { else {