Bug 248608 - [patch] off-by-one alignment in ipfw -t list
Summary: [patch] off-by-one alignment in ipfw -t list
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Ed Maste
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-11 20:14 UTC by Taylor Stearns
Modified: 2020-08-21 19:32 UTC (History)
1 user (show)

See Also:


Attachments
ipfw off-by-one patch (331 bytes, patch)
2020-08-11 20:14 UTC, Taylor Stearns
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Taylor Stearns 2020-08-11 20:14:37 UTC
Created attachment 217162 [details]
ipfw off-by-one patch

When I run `ipfw -t list` on release/12 or current, I get misaligned output between lines that do and do not have a last match timestamp, like so:

00100 Tue Aug 11 03:03:26 2020 allow ip from any to any via lo0
00200                         deny ip from any to 127.0.0.0/8

(specifically, the "allow" and "deny" strings do not line up)

This appears to be a simple off-by-one logic error in ipfw2.c. The routine `ipfw_list` calculates the number of characters that a date string takes up, called `twidth`, then prints one of the following:

If a match timestamp exists, then twidth date characters are printed, followed by a space, followed by the rule string.

If a match timestamp does not exist, then twidth spaces are printed, followed by the rule string.

The correct behavior would be to print twidth characters followed by a space for both code paths, as is done in the attached patch. After applying this patch locally, I get correct results:

00100 Tue Aug 11 03:03:26 2020 allow ip from any to any via lo0
00200                          deny ip from any to 127.0.0.0/8
Comment 1 commit-hook freebsd_committer 2020-08-17 18:53:58 UTC
A commit references this bug:

Author: emaste
Date: Mon Aug 17 18:53:23 UTC 2020
New revision: 364321
URL: https://svnweb.freebsd.org/changeset/base/364321

Log:
  ipfw: line up `ipfw -t list` with and without timestamp

  From the PR:
      When I run `ipfw -t list` on release/12 or current, I get misaligned
      output between lines that do and do not have a last match timestamp,
      like so:

      00100 Tue Aug 11 03:03:26 2020 allow ip from any to any via lo0
      00200                         deny ip from any to 127.0.0.0/8

      (specifically, the "allow" and "deny" strings do not line up)

  PR:		248608
  Submitted by:	Taylor Stearns
  MFC after:	3 days

Changes:
  head/sbin/ipfw/ipfw2.c
Comment 2 commit-hook freebsd_committer 2020-08-21 19:29:17 UTC
A commit references this bug:

Author: emaste
Date: Fri Aug 21 19:28:27 UTC 2020
New revision: 364461
URL: https://svnweb.freebsd.org/changeset/base/364461

Log:
  MFC r364321: ipfw: line up `ipfw -t list` with and without timestamp

  From the PR:
      When I run `ipfw -t list` on release/12 or current, I get misaligned
      output between lines that do and do not have a last match timestamp,
      like so:

      00100 Tue Aug 11 03:03:26 2020 allow ip from any to any via lo0
      00200                         deny ip from any to 127.0.0.0/8

      (specifically, the "allow" and "deny" strings do not line up)

  PR:		248608
  Submitted by:	Taylor Stearns

Changes:
_U  stable/12/
  stable/12/sbin/ipfw/ipfw2.c