Bug 231323 - pfctl parser error
Summary: pfctl parser error
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.2-STABLE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-pf (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-09-12 09:32 UTC by pr
Modified: 2018-11-18 09:49 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pr 2018-09-12 09:32:28 UTC
pfctl fails to load certain configuration. I have reduced the sample configuration as follows (does not make sense now, but demonstrates the problem):

export MALLOC_CONF=junk:true

pfctl -n -f - <<EOF
rdr on em0 proto tcp from any to any -> 1.1.1.1 port 2121
pass out log quick on lo0 route-to lo0 from any to any
pass in log quick on lo0 route-to (lo0 localhost) from any to any
EOF

produces:
pfctl: expand_rule: strlcpy

This behavior seems to appear in FreeBSD 11.2 (the error did not display in FreeBSD 11.1).

Pavel Rydvan
Comment 1 Kristof Provost freebsd_committer freebsd_triage 2018-09-12 12:52:42 UTC
Can you test this patch?

diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y
index 3b1f0bbea3d..c542bf72f70 100644
--- a/sbin/pfctl/parse.y
+++ b/sbin/pfctl/parse.y
@@ -4408,7 +4408,7 @@ route_host        : STRING                        {
                        $$ = calloc(1, sizeof(struct node_host));
                        if ($$ == NULL)
                                err(1, "route_host: calloc");
-                       $$->ifname = $1;
+                       $$->ifname = strdup($1);
                        set_ipmask($$, 128);
                        $$->next = NULL;
                        $$->tail = $$;
@@ -4418,7 +4418,7 @@ route_host        : STRING                        {

                        $$ = $3;
                        for (n = $3; n != NULL; n = n->next)
-                               n->ifname = $2;
+                               n->ifname = strdup($2);
                }
                ;
Comment 2 pr 2018-09-12 13:22:47 UTC
(In reply to Kristof Provost from comment #1)

Yes, this helps. Thanks!

Pavel
Comment 3 commit-hook freebsd_committer freebsd_triage 2018-10-20 18:12:21 UTC
A commit references this bug:

Author: kp
Date: Sat Oct 20 18:11:47 UTC 2018
New revision: 339464
URL: https://svnweb.freebsd.org/changeset/base/339464

Log:
  pfctl: Dup strings

  When we set the ifname we have to copy the string, rather than just keep
  the pointer.

  PR:		231323
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D17507

Changes:
  head/sbin/pfctl/parse.y
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-10-20 18:19:31 UTC
A commit references this bug:

Author: kp
Date: Sat Oct 20 18:18:29 UTC 2018
New revision: 339466
URL: https://svnweb.freebsd.org/changeset/base/339466

Log:
  pfctl tests: Basic test case for PR 231323

  PR:		231323
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D17508

Changes:
  head/sbin/pfctl/tests/files/pf1005.in
  head/sbin/pfctl/tests/files/pf1005.ok
  head/sbin/pfctl/tests/files/pfctl_test_descr.sh
  head/sbin/pfctl/tests/pfctl_test.sh
Comment 5 commit-hook freebsd_committer freebsd_triage 2018-11-18 09:47:41 UTC
A commit references this bug:

Author: kp
Date: Sun Nov 18 09:47:30 UTC 2018
New revision: 340549
URL: https://svnweb.freebsd.org/changeset/base/340549

Log:
  MFC r339464:

  pfctl: Dup strings

  When we set the ifname we have to copy the string, rather than just keep
  the pointer.

  PR:		231323

Changes:
_U  stable/12/
  stable/12/sbin/pfctl/parse.y
Comment 6 commit-hook freebsd_committer freebsd_triage 2018-11-18 09:48:45 UTC
A commit references this bug:

Author: kp
Date: Sun Nov 18 09:47:40 UTC 2018
New revision: 340550
URL: https://svnweb.freebsd.org/changeset/base/340550

Log:
  MFC r339464:

  pfctl: Dup strings

  When we set the ifname we have to copy the string, rather than just keep
  the pointer.

  PR:		231323

Changes:
_U  stable/11/
  stable/11/sbin/pfctl/parse.y
Comment 7 commit-hook freebsd_committer freebsd_triage 2018-11-18 09:49:48 UTC
A commit references this bug:

Author: kp
Date: Sun Nov 18 09:48:52 UTC 2018
New revision: 340551
URL: https://svnweb.freebsd.org/changeset/base/340551

Log:
  MFC r339466:

  pfctl tests: Basic test case for PR 231323

  PR:		231323

Changes:
_U  stable/12/
  stable/12/sbin/pfctl/tests/files/pf1005.in
  stable/12/sbin/pfctl/tests/files/pf1005.ok
  stable/12/sbin/pfctl/tests/files/pfctl_test_descr.sh
  stable/12/sbin/pfctl/tests/pfctl_test.sh