#include "common.h"
#include <wordsplit.h>
-
#include <flexmember.h>
-#include <fprintftime.h>
#include <sys/ioctl.h>
#include <termios.h>
}
}
+/* Get the number of columns in the FP output stream.
+ FIXME: The rest of the code counts bytes, not columns,
+ so columns don't line up if multi-byte characters are output. */
static intmax_t
getwidth (FILE *fp)
{
case 't':
{
struct timespec ts = current_timespec ();
- const char *fmt = arg ? arg : "%c";
struct tm *tm = localtime (&ts.tv_sec);
- len = add_printf (len,
- (tm ? fprintftime (fp, fmt, tm, 0, ts.tv_nsec)
- : fprintf (fp, "????""-??""-?? ??:??:??")));
+ char const *tmstr = NULL;
+
+ /* Keep BUF relatively small, as any text timestamp
+ not fitting into BUF is likely a DoS attack. */
+ char buf[max (SYSINT_BUFSIZE, 256)];
+
+ if (tm)
+ {
+ buf[0] = '\0';
+ char const *fmt = arg ? arg : "%c";
+ if (strftime (buf, sizeof buf, fmt, tm) != 0 || !buf[0])
+ tmstr = buf;
+ }
+ if (!tmstr)
+ tmstr = timetostr (ts.tv_sec, buf);
+ len = add_printf (len, fprintf (fp, "%s", tmstr));
}
break;