diff -ruN simpleinit-msb-1.3/login-utils/shutdown.c simpleinit-msb-1.3.utmplimit/login-utils/shutdown.c --- simpleinit-msb-1.3/login-utils/shutdown.c 2025-02-28 11:15:00.229663783 +0100 +++ simpleinit-msb-1.3.utmplimit/login-utils/shutdown.c 2025-02-28 11:08:04.528663832 +0100 @@ -116,6 +116,7 @@ #include "pathnames.h" #include "xstrncpy.h" #include "nls.h" +#include "../utmp_time.h" static void usage(void), int_handler(int), write_user(struct utmp *); static void wall(void), write_wtmp(void), unmount_disks(void); @@ -584,12 +585,16 @@ #define TERM_PREFIX "/dev/" char term[40] = TERM_PREFIX; char msg[266]; + /* keep space for terminating 0, be prepared for non-terminated ut_line */ + size_t termlimit = sizeof(term) - sizeof(TERM_PREFIX) - 1; + if(termlimit > UT_LINESIZE) + termlimit = UT_LINESIZE; minutes = timeout / 60; hours = minutes / 60; minutes %= 60; - strncat(term, ut->ut_line, sizeof(term) - sizeof(TERM_PREFIX)); + strncat(term, ut->ut_line, termlimit); /* try not to get stuck on a mangled ut_line entry... */ if((fd = open(term, O_WRONLY|O_NONBLOCK)) < 0) @@ -652,7 +657,7 @@ strcpy(ut.ut_line, "~"); strcpy(ut.ut_name, "shutdown"); - time(&ut.ut_time); + utmp_time(&ut); /* communicate error? */ ut.ut_type = BOOT_TIME; if((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0644)) >= 0) { diff -ruN simpleinit-msb-1.3/login-utils/simpleinit.c simpleinit-msb-1.3.utmplimit/login-utils/simpleinit.c --- simpleinit-msb-1.3/login-utils/simpleinit.c 2025-02-28 11:15:00.229663783 +0100 +++ simpleinit-msb-1.3.utmplimit/login-utils/simpleinit.c 2025-02-28 11:16:27.983663772 +0100 @@ -229,6 +229,7 @@ #include "xstrncpy.h" #include "nls.h" #include "simpleinit.h" +#include "../utmp_time.h" #define MAXPARAMS 128 /* max num of args you can use with ctrlaltdel prog */ #define CMDSIZ 150 /* max size of a line in inittab */ @@ -522,7 +523,7 @@ setutent(); while((ut = getutent())) { if(ut->ut_pid == pid) { - time(&ut->ut_time); + utmp_time(ut); /* communicate error? */ memset(&ut->ut_user, 0, UT_NAMESIZE); memset(&ut->ut_host, 0, sizeof(ut->ut_host)); ut->ut_type = DEAD_PROCESS; @@ -1064,7 +1065,7 @@ memset((char *)&ut, 0, sizeof(ut)); strcpy(ut.ut_line, "~"); memset(ut.ut_name, 0, sizeof(ut.ut_name)); - time(&ut.ut_time); + utmp_time(&ut); /* communicate error? */ ut.ut_type = BOOT_TIME; #ifdef HAVE_updwtmp updwtmp(_path_wtmp,&ut); @@ -1118,7 +1119,7 @@ ut.ut_id[1]=(id/100)%10+'0'; ut.ut_id[0]=(id/1000)%10+'0'; - time(&ut.ut_time); + utmp_time(&ut); /* communicate error? */ pututline(&ut); endutent(); } diff -ruN simpleinit-msb-1.3/sysvtools/utmp.c simpleinit-msb-1.3.utmplimit/sysvtools/utmp.c --- simpleinit-msb-1.3/sysvtools/utmp.c 2007-11-08 21:13:15.000000000 +0100 +++ simpleinit-msb-1.3.utmplimit/sysvtools/utmp.c 2025-02-28 10:46:22.246663988 +0100 @@ -21,7 +21,7 @@ #include "init.h" #include "initreq.h" #include "paths.h" - +#include "../utmp_time.h" #if defined(__GLIBC__) # if (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0) && defined(__powerpc__) @@ -78,7 +78,7 @@ #if defined(__GLIBC__) gettimeofday(&utmp.ut_tv, NULL); #else - time(&utmp.ut_time); + utmp_time(&utmp); /* communicate error? */ #endif utmp.ut_pid = pid; utmp.ut_type = type; @@ -143,11 +143,7 @@ utmp.ut_type = type; utmp.ut_pid = pid; strncpy(utmp.ut_id, id, sizeof(utmp.ut_id)); -#if defined(__GLIBC__) - gettimeofday(&utmp.ut_tv, NULL); -#else - time(&utmp.ut_time); -#endif + utmp_time(&utmp); /* communicate error? */ strncpy(utmp.ut_user, user, UT_NAMESIZE); if (line) strncpy(utmp.ut_line, line, UT_LINESIZE); diff -ruN simpleinit-msb-1.3/sysvtools/wall.c simpleinit-msb-1.3.utmplimit/sysvtools/wall.c --- simpleinit-msb-1.3/sysvtools/wall.c 2007-11-08 21:13:16.000000000 +0100 +++ simpleinit-msb-1.3.utmplimit/sysvtools/wall.c 2025-02-28 11:09:08.442663825 +0100 @@ -101,7 +101,7 @@ } openlog("wall", LOG_PID, LOG_USER); - syslog(LOG_INFO, "wall: user %s broadcasted %d lines (%d chars)", + syslog(LOG_INFO, "wall: user %s broadcasted %d lines (%zu chars)", whoami, i, strlen(buf)); closelog(); diff -ruN simpleinit-msb-1.3/utmp_time.h simpleinit-msb-1.3.utmplimit/utmp_time.h --- simpleinit-msb-1.3/utmp_time.h 1970-01-01 01:00:00.000000000 +0100 +++ simpleinit-msb-1.3.utmplimit/utmp_time.h 2025-02-28 11:13:02.972663797 +0100 @@ -0,0 +1,28 @@ +#ifndef UTMP_TIME_H +#define UTMP_TIME_H + +#include +#include +#include + +static int utmp_time(struct utmp *ut) +{ + struct timeval tv; + int ret = 0; + ret = gettimeofday(&tv, NULL); + if(!ret) + { + /* Better handling of overflow here? This could be 64 bit time_t to + 32 bit (unsigned) integer. */ + ut->ut_tv.tv_sec = tv.tv_sec; + ut->ut_tv.tv_usec = tv.tv_usec; + if(ut->ut_tv.tv_sec != tv.tv_sec || ut->ut_tv.tv_usec != tv.tv_usec) + { + ret = -1; + errno = EOVERFLOW; + } + } + return ret; +} + +#endif .