sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 5800c117e2744b00d32f747fab123eb581bb4722
parent 261f5bffa52802eaab7131e5edd25568d197709a
Author: Mattias Andrée <maandree@kth.se>
Date:   Sun Mar 27 14:49:45 +0200

ls: fix segfault when timestamp is out of range for struct tm

Signed-off-by: Mattias Andrée <maandree@kth.se>

Diffstat:
ls.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/ls.c b/ls.c @@ -118,6 +118,7 @@ output(const struct entry *ent) { struct group *gr; struct passwd *pw; + struct tm *tm; ssize_t len; size_t l; char *name, *c, *u, *fmt, buf[BUFSIZ], @@ -194,7 +195,10 @@ output(const struct entry *ent) else fmt = "%b %d %H:%M"; - strftime(buf, sizeof(buf), fmt, localtime(&ent->t.tv_sec)); + if ((tm = localtime(&ent->t.tv_sec))) + strftime(buf, sizeof(buf), fmt, tm); + else + snprintf(buf, sizeof(buf), "%lld", (long long)(ent->t.tv_sec)); printf("%s %4ld %-8.8s %-8.8s ", mode, (long)ent->nlink, pwname, grname); if (S_ISBLK(ent->mode) || S_ISCHR(ent->mode))