Bug 232642

Summary: sbin/ipfw show: segfault on parsing setdscp rules
Product: Base System Reporter: Sergey Akhmatov <sergey>
Component: binAssignee: Andrey V. Elsukov <ae>
Status: Closed FIXED    
Severity: Affects Only Me CC: bugs.freebsd.org
Priority: --- Keywords: patch
Version: CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
sbin/ipfw/ipfw2.c - fix ipfw show for rules with setdscp action none

Description Sergey Akhmatov 2018-10-24 16:44:59 UTC
Created attachment 198583 [details]
sbin/ipfw/ipfw2.c - fix ipfw show for rules with setdscp action

ipfw show fails to show rules with "setdscp" action for DSCP code values without matching well-known class name.

Steps to reproduce:
# ipfw add 1000 setdscp 10 ip from any to any
01000 setdscp af11 ip from any to any
# ipfw add 1001 setdscp 11 ip from any to any
segmentation fault

# ipfw show 1000
01000   0     0 setdscp af11 ip from any to any
# ipfw show 1001
segmentation fault

The bug was introduced in r331668. 11.2-RELEASE and 12.0-BETA1 are affected.

Problem code in sbin/ipfw/ipfw2.c as follows:
---
        case O_SETDSCP:
                if (cmd->arg1 == IP_FW_TARG) {
                        bprintf(bp, "setdscp tablearg");
                        break;
                }
                s = match_value(f_ipdscp, cmd->arg1 & 0x3F);
                if (s != NULL)
                        bprintf(bp, "setdscp %s", s);
                else
                        bprintf(bp, "setdscp %s", cmd->arg1 & 0x3F);
---
cmd->arg1 is int, but is passed to "%s" format specifier. Changing it to "%d" fixes things for me.
Comment 1 commit-hook freebsd_committer freebsd_triage 2018-10-25 18:07:23 UTC
A commit references this bug:

Author: ae
Date: Thu Oct 25 18:06:23 UTC 2018
New revision: 339740
URL: https://svnweb.freebsd.org/changeset/base/339740

Log:
  Use correct format specificator to print setdscp action.

  PR:		232642
  MFC after:	3 days

Changes:
  head/sbin/ipfw/ipfw2.c
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2018-10-26 10:16:44 UTC
Over to committer for possible MFC.
Comment 3 commit-hook freebsd_committer freebsd_triage 2018-10-28 18:22:14 UTC
A commit references this bug:

Author: ae
Date: Sun Oct 28 18:21:14 UTC 2018
New revision: 339841
URL: https://svnweb.freebsd.org/changeset/base/339841

Log:
  MFC r339740:
    Use correct format specificator to print setdscp action.

    PR:		232642
  Approved by:	re (rgrimes)

Changes:
_U  stable/12/
  stable/12/sbin/ipfw/ipfw2.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-10-28 18:23:17 UTC
A commit references this bug:

Author: ae
Date: Sun Oct 28 18:23:14 UTC 2018
New revision: 339842
URL: https://svnweb.freebsd.org/changeset/base/339842

Log:
  MFC r339740:
    Use correct format specificator to print setdscp action.

    PR:		232642

Changes:
_U  stable/11/
  stable/11/sbin/ipfw/ipfw2.c
Comment 5 Andrey V. Elsukov freebsd_committer freebsd_triage 2018-10-28 18:24:00 UTC
Fixed in head, stable/12 and stable/11. Thanks!
Comment 6 Andrey V. Elsukov freebsd_committer freebsd_triage 2018-11-03 15:44:26 UTC
*** Bug 232917 has been marked as a duplicate of this bug. ***