Date: Sun, 9 May 2021 12:35:18 GMT From: Lutz Donnerhacke <donner@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 80b22e631506 - stable/13 - sbin/ipfw: Fix null pointer deference when printing counters Message-ID: <202105091235.149CZIKn022749@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by donner: URL: https://cgit.FreeBSD.org/src/commit/?id=80b22e631506a3d6d783fa42424502d32d1f417f commit 80b22e631506a3d6d783fa42424502d32d1f417f Author: Lutz Donnerhacke <donner@FreeBSD.org> AuthorDate: 2021-04-30 14:12:47 +0000 Commit: Lutz Donnerhacke <donner@FreeBSD.org> CommitDate: 2021-05-09 12:33:28 +0000 sbin/ipfw: Fix null pointer deference when printing counters ipfw -[tT] prints statistics of the last access. If the rule was never used, the counter might be not exist. This happens unconditionally on inserting a new rule. Avoid printing statistics in this case. PR: 255491 Reported by: Haisheng Zhouz Reviewed by: ae Differential Revision: https://reviews.freebsd.org/D30046 (cherry picked from commit bf7cc0f9cb6603a6bdd6131c8d1939724ce6e62d) --- sbin/ipfw/ipfw2.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c index 19f7f331091d..c17fbbca7dfa 100644 --- a/sbin/ipfw/ipfw2.c +++ b/sbin/ipfw/ipfw2.c @@ -2174,32 +2174,35 @@ show_static_rule(struct cmdline_opts *co, struct format_opts *fo, } bprintf(bp, "%05u ", rule->rulenum); - /* Print counters if enabled */ - if (fo->pcwidth > 0 || fo->bcwidth > 0) { - pr_u64(bp, &cntr->pcnt, fo->pcwidth); - pr_u64(bp, &cntr->bcnt, fo->bcwidth); - } - - /* Print timestamp */ - if (co->do_time == TIMESTAMP_NUMERIC) - bprintf(bp, "%10u ", cntr->timestamp); - else if (co->do_time == TIMESTAMP_STRING) { - char timestr[30]; - time_t t = (time_t)0; - - if (twidth == 0) { - strcpy(timestr, ctime(&t)); - *strchr(timestr, '\n') = '\0'; - twidth = strlen(timestr); + /* only if counters are available */ + if (cntr != NULL) { + /* Print counters if enabled */ + if (fo->pcwidth > 0 || fo->bcwidth > 0) { + pr_u64(bp, &cntr->pcnt, fo->pcwidth); + pr_u64(bp, &cntr->bcnt, fo->bcwidth); } - if (cntr->timestamp > 0) { - t = _long_to_time(cntr->timestamp); - strcpy(timestr, ctime(&t)); - *strchr(timestr, '\n') = '\0'; - bprintf(bp, "%s ", timestr); - } else { - bprintf(bp, "%*s ", twidth, ""); + /* Print timestamp */ + if (co->do_time == TIMESTAMP_NUMERIC) + bprintf(bp, "%10u ", cntr->timestamp); + else if (co->do_time == TIMESTAMP_STRING) { + char timestr[30]; + time_t t = (time_t)0; + + if (twidth == 0) { + strcpy(timestr, ctime(&t)); + *strchr(timestr, '\n') = '\0'; + twidth = strlen(timestr); + } + if (cntr->timestamp > 0) { + t = _long_to_time(cntr->timestamp); + + strcpy(timestr, ctime(&t)); + *strchr(timestr, '\n') = '\0'; + bprintf(bp, "%s ", timestr); + } else { + bprintf(bp, "%*s ", twidth, ""); + } } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105091235.149CZIKn022749>