[hackers] [sbase][PATCH] ls: fix segfault when timestamp is negative

From: Mattias Andrée <maandree_AT_kth.se>
Date: Sun, 27 Mar 2016 14:50:52 +0200

Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
---
 ls.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/ls.c b/ls.c
index 3268a99..8a9210c 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -194,7 +194,10 @@ output(const struct entry *ent)
 	else
 		fmt = "%b %d %H:%M";
 
-	strftime(buf, sizeof(buf), fmt, localtime(&ent->t.tv_sec));
+	if (ent->t.tv_sec < 0)
+		snprintf(buf, sizeof(buf), "%lli", (long long)(ent->t.tv_sec));
+	else
+		strftime(buf, sizeof(buf), fmt, localtime(&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))
-- 
2.7.4
Received on Sun Mar 27 2016 - 14:50:52 CEST

This archive was generated by hypermail 2.3.0 : Sun Mar 27 2016 - 15:00:24 CEST