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/pfctl | |
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/pfctl')
-rw-r--r-- | sbin/pfctl/pfctl_table.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/sbin/pfctl/pfctl_table.c b/sbin/pfctl/pfctl_table.c index ba21402943d..6443126900e 100644 --- a/sbin/pfctl/pfctl_table.c +++ b/sbin/pfctl/pfctl_table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_table.c,v 1.87 2024/01/15 07:23:32 sashan Exp $ */ +/* $OpenBSD: pfctl_table.c,v 1.88 2024/05/09 08:35:40 florian Exp $ */ /* * Copyright (c) 2002 Cedric Berger @@ -389,14 +389,19 @@ print_table(struct pfr_table *ta, int verbose, int debug) void print_tstats(struct pfr_tstats *ts, int debug) { - time_t time = ts->pfrts_tzero; - int dir, op; + time_t time = ts->pfrts_tzero; + int dir, op; + char *ct; if (!debug && !(ts->pfrts_flags & PFR_TFLAG_ACTIVE)) return; + ct = ctime(&time); print_table(&ts->pfrts_t, 1, debug); printf("\tAddresses: %d\n", ts->pfrts_cnt); - printf("\tCleared: %s", ctime(&time)); + if (ct) + printf("\tCleared: %s", ct); + else + printf("\tCleared: %lld\n", time); printf("\tReferences: [ Anchors: %-18d Rules: %-18d ]\n", ts->pfrts_refcnt[PFR_REFCNT_ANCHOR], ts->pfrts_refcnt[PFR_REFCNT_RULE]); @@ -487,11 +492,16 @@ print_addrx(struct pfr_addr *ad, struct pfr_addr *rad, int dns) void print_astats(struct pfr_astats *as, int dns) { - time_t time = as->pfras_tzero; - int dir, op; + time_t time = as->pfras_tzero; + int dir, op; + char *ct; + ct = ctime(&time); print_addrx(&as->pfras_a, NULL, dns); - printf("\tCleared: %s", ctime(&time)); + if (ct) + printf("\tCleared: %s", ctime(&time)); + else + printf("\tCleared: %lld\n", time); if (as->pfras_a.pfra_states) printf("\tActive States: %d\n", as->pfras_a.pfra_states); if (as->pfras_a.pfra_type == PFRKE_COST) @@ -603,8 +613,9 @@ pfctl_show_ifaces(const char *filter, int opts) void print_iface(struct pfi_kif *p, int opts) { - time_t tzero = p->pfik_tzero; - int i, af, dir, act; + time_t tzero = p->pfik_tzero; + int i, af, dir, act; + char *ct; printf("%s", p->pfik_name); if (opts & PF_OPT_VERBOSE) { @@ -615,7 +626,12 @@ print_iface(struct pfi_kif *p, int opts) if (!(opts & PF_OPT_VERBOSE2)) return; - printf("\tCleared: %s", ctime(&tzero)); + + ct = ctime(&tzero); + if (ct) + printf("\tCleared: %s", ct); + else + printf("\tCleared: %lld\n", tzero); printf("\tReferences: [ States: %-18d Rules: %-18d ]\n", p->pfik_states, p->pfik_rules); for (i = 0; i < 8; i++) { |