diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2024-05-09 08:35:42 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2024-05-09 08:35:42 +0000 |
commit | 13192d4193dfa5873036694f4ad76472a1c0a3e3 (patch) | |
tree | 50d3ab0b83388be65a11f3bc0fb32e1bf1483339 /sbin/dumpfs | |
parent | 9243a6b7a514d95e7618fdee4bad66710b0fff13 (diff) |
ctime(3) and ctime_r(3) can fail when timestamps are way off.
Add missing error checks to all calls under sbin/
Input kettenis, millert
OK millert
Diffstat (limited to 'sbin/dumpfs')
-rw-r--r-- | sbin/dumpfs/dumpfs.c | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/sbin/dumpfs/dumpfs.c b/sbin/dumpfs/dumpfs.c index 481f5b41e95..c4e2fda8a0f 100644 --- a/sbin/dumpfs/dumpfs.c +++ b/sbin/dumpfs/dumpfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dumpfs.c,v 1.38 2024/02/03 18:51:57 beck Exp $ */ +/* $OpenBSD: dumpfs.c,v 1.39 2024/05/09 08:35:40 florian Exp $ */ /* * Copyright (c) 2002 Networks Associates Technology, Inc. @@ -163,13 +163,19 @@ dumpfs(int fd, const char *name) off_t off; int i, j; u_int cg; + char *ct; switch (afs.fs_magic) { case FS_UFS2_MAGIC: fssize = afs.fs_size; fstime = afs.fs_time; - printf("magic\t%x (FFS2)\ttime\t%s", - afs.fs_magic, ctime(&fstime)); + ct = ctime(&fstime); + if (ct) + printf("magic\t%x (FFS2)\ttime\t%s", + afs.fs_magic, ctime(&fstime)); + else + printf("magic\t%x (FFS2)\ttime\t%lld\n", + afs.fs_magic, fstime); printf("superblock location\t%jd\tid\t[ %x %x ]\n", (intmax_t)afs.fs_sblockloc, afs.fs_id[0], afs.fs_id[1]); printf("ncg\t%u\tsize\t%jd\tblocks\t%jd\n", @@ -178,8 +184,13 @@ dumpfs(int fd, const char *name) case FS_UFS1_MAGIC: fssize = afs.fs_ffs1_size; fstime = afs.fs_ffs1_time; - printf("magic\t%x (FFS1)\ttime\t%s", - afs.fs_magic, ctime(&fstime)); + ct = ctime(&fstime); + if (ct) + printf("magic\t%x (FFS1)\ttime\t%s", + afs.fs_magic, ctime(&fstime)); + else + printf("magic\t%x (FFS1)\ttime\t%lld\n", + afs.fs_magic, fstime); printf("id\t[ %x %x ]\n", afs.fs_id[0], afs.fs_id[1]); i = 0; if (afs.fs_postblformat != FS_42POSTBLFMT) { @@ -325,6 +336,7 @@ dumpcg(const char *name, int fd, u_int c) time_t cgtime; off_t cur; int i, j; + char *ct; printf("\ncg %u:\n", c); cur = (off_t)fsbtodb(&afs, cgtod(&afs, c)) * DEV_BSIZE; @@ -335,18 +347,30 @@ dumpcg(const char *name, int fd, u_int c) switch (afs.fs_magic) { case FS_UFS2_MAGIC: cgtime = acg.cg_ffs2_time; - printf("magic\t%x\ttell\t%jx\ttime\t%s", - acg.cg_magic, (intmax_t)cur, ctime(&cgtime)); + ct = ctime(&cgtime); + if (ct) + printf("magic\t%x\ttell\t%jx\ttime\t%s", + acg.cg_magic, (intmax_t)cur, ct); + else + printf("magic\t%x\ttell\t%jx\ttime\t%lld\n", + acg.cg_magic, (intmax_t)cur, cgtime); printf("cgx\t%u\tndblk\t%u\tniblk\t%u\tinitiblk %u\n", acg.cg_cgx, acg.cg_ndblk, acg.cg_ffs2_niblk, acg.cg_initediblk); break; case FS_UFS1_MAGIC: cgtime = acg.cg_time; - printf("magic\t%x\ttell\t%jx\ttime\t%s", - afs.fs_postblformat == FS_42POSTBLFMT ? - ((struct ocg *)&acg)->cg_magic : acg.cg_magic, - (intmax_t)cur, ctime(&cgtime)); + ct = ctime(&cgtime); + if (ct) + printf("magic\t%x\ttell\t%jx\ttime\t%s", + afs.fs_postblformat == FS_42POSTBLFMT ? + ((struct ocg *)&acg)->cg_magic : acg.cg_magic, + (intmax_t)cur, ct); + else + printf("magic\t%x\ttell\t%jx\ttime\t%lld\n", + afs.fs_postblformat == FS_42POSTBLFMT ? + ((struct ocg *)&acg)->cg_magic : acg.cg_magic, + (intmax_t)cur, cgtime); printf("cgx\t%u\tncyl\t%d\tniblk\t%d\tndblk\t%u\n", acg.cg_cgx, acg.cg_ncyl, acg.cg_niblk, acg.cg_ndblk); break; |