ls: fix segfault when timestamp is out of range for struct tm
Signed-off-by: Mattias Andrée <maandree@kth.se>
This commit is contained in:
parent
33c5c71e01
commit
dfc94e0221
6
ls.c
6
ls.c
|
@ -118,6 +118,7 @@ output(const struct entry *ent)
|
||||||
{
|
{
|
||||||
struct group *gr;
|
struct group *gr;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
struct tm *tm;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
size_t l;
|
size_t l;
|
||||||
char *name, *c, *u, *fmt, buf[BUFSIZ],
|
char *name, *c, *u, *fmt, buf[BUFSIZ],
|
||||||
|
@ -194,7 +195,10 @@ output(const struct entry *ent)
|
||||||
else
|
else
|
||||||
fmt = "%b %d %H:%M";
|
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);
|
printf("%s %4ld %-8.8s %-8.8s ", mode, (long)ent->nlink, pwname, grname);
|
||||||
|
|
||||||
if (S_ISBLK(ent->mode) || S_ISCHR(ent->mode))
|
if (S_ISBLK(ent->mode) || S_ISCHR(ent->mode))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user