Bug 263240 - IPFW tools: Parsing error in nat config port_range
Summary: IPFW tools: Parsing error in nat config port_range
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-ipfw (Nobody)
URL:
Keywords:
: 288322 (view as bug list)
Depends on:
Blocks: 288380
  Show dependency treegraph
 
Reported: 2022-04-12 14:10 UTC by Andrey Linkevich
Modified: 2026-06-07 09:12 UTC (History)
5 users (show)

See Also:


Attachments
IPFW NAT config: port range parsing fix (385 bytes, patch)
2022-04-12 14:10 UTC, Andrey Linkevich
no flags Details | Diff
IPFW NAT config: port range parsing fix (405 bytes, patch)
2025-02-27 17:10 UTC, Mark Linimon
no flags Details | Diff
fix for port range parsing (365 bytes, patch)
2025-02-28 09:31 UTC, Eugene Perevyazko
no flags Details | Diff
fix for port range parsing (2) (467 bytes, patch)
2025-06-23 09:55 UTC, Vyacheslav
no flags Details | Diff
nat.c.patch (487 bytes, patch)
2025-09-20 22:19 UTC, Mark Linimon
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Linkevich 2022-04-12 14:10:44 UTC
Created attachment 233165 [details]
IPFW NAT config: port range parsing fix

Hello, Colleagues.

In ipfw error with parsing "ipfw nat 11 config port_range 1025-65535". Forever "You need a range of port(s) from 1024 <= x < 65536".

Two errors in /usr/src/sbin/ipfw/nat.c nat_port_alias_parse().

Patch attached.

Thanks.
Comment 1 Lutz Donnerhacke freebsd_committer freebsd_triage 2022-04-13 06:44:38 UTC
Thank you for reporting this issue.

I wonder why the error occurs at all.
Somebody should tested this during development.
Comment 2 Yuri 2022-04-13 07:03:08 UTC
You don't need the checks for !ptr (which should have been written as ptr == NULL anyway), strtol() does not seem to set endptr to NULL ever.
Comment 3 Alexander 2022-11-06 14:40:12 UTC
Also after applying the patch nat_show_cfg() doesn't display port_range by cmd:

ipfw nat 1 show config

But looks like the patch works regardless of a room for improvement there
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2024-09-25 10:27:03 UTC
^Triage: committer's bit was taken in for safekeeping.
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2025-02-27 17:10:33 UTC
Created attachment 258037 [details]
IPFW NAT config: port range parsing fix

^Triage: rebase patch.
Comment 6 Eugene Perevyazko 2025-02-28 09:31:24 UTC
Created attachment 258057 [details]
fix for port range parsing

I wonder if this won't be enough (check for dash presence, check there is something after dash and try to parse it)
Comment 7 Vyacheslav 2025-06-23 09:55:53 UTC
Created attachment 261503 [details]
fix for port range parsing (2)

The patch from the attachment solved the problem of parsing the port range for me, the values ​​are correctly passed to libalias, ipfw nat works as expected.
Comment 8 Tatsuki Makino 2025-07-22 08:41:02 UTC
*** Bug 288322 has been marked as a duplicate of this bug. ***
Comment 9 Mark Linimon freebsd_committer freebsd_triage 2025-09-20 22:19:27 UTC
Created attachment 263952 [details]
nat.c.patch

^Triage: rebase patch so that it applies.
Comment 10 commit-hook freebsd_committer freebsd_triage 2026-05-21 08:11:16 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=6eba055fcf5b0bbfbebcac59f5982d13815001b0

commit 6eba055fcf5b0bbfbebcac59f5982d13815001b0
Author:     Vyacheslav Terehov <terehovv@mail.ru>
AuthorDate: 2026-05-21 07:15:22 +0000
Commit:     Andrey V. Elsukov <ae@FreeBSD.org>
CommitDate: 2026-05-21 07:15:22 +0000

    ipfw: fix parsing error in nat config port_range

    Also fix the corresponding tests.

    PR:             263240
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D57010

 sbin/ipfw/ipfw.8                |  3 ++-
 sbin/ipfw/nat.c                 | 29 ++++++++++++++++-------------
 tests/sys/netpfil/common/nat.sh | 26 ++++++++++++++------------
 3 files changed, 32 insertions(+), 26 deletions(-)
Comment 11 commit-hook freebsd_committer freebsd_triage 2026-05-29 08:02:59 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=33cafd3fadd07ea49b18559a4fe397951c6a844f

commit 33cafd3fadd07ea49b18559a4fe397951c6a844f
Author:     Vyacheslav Terehov <terehovv@mail.ru>
AuthorDate: 2026-05-21 07:15:22 +0000
Commit:     Andrey V. Elsukov <ae@FreeBSD.org>
CommitDate: 2026-05-29 08:01:00 +0000

    ipfw: fix parsing error in nat config port_range

    Also fix the corresponding tests.

    PR:             263240
    Differential Revision:  https://reviews.freebsd.org/D57010

    (cherry picked from commit 6eba055fcf5b0bbfbebcac59f5982d13815001b0)

 sbin/ipfw/ipfw.8                |  3 ++-
 sbin/ipfw/nat.c                 | 29 ++++++++++++++++-------------
 tests/sys/netpfil/common/nat.sh | 26 ++++++++++++++------------
 3 files changed, 32 insertions(+), 26 deletions(-)
Comment 12 commit-hook freebsd_committer freebsd_triage 2026-05-29 08:05:03 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d2e63a09519364f9a9e328666302b28d7ee95c47

commit d2e63a09519364f9a9e328666302b28d7ee95c47
Author:     Vyacheslav Terehov <terehovv@mail.ru>
AuthorDate: 2026-05-21 07:15:22 +0000
Commit:     Andrey V. Elsukov <ae@FreeBSD.org>
CommitDate: 2026-05-29 08:02:49 +0000

    ipfw: fix parsing error in nat config port_range

    Also fix the corresponding tests.

    PR:             263240
    Differential Revision:  https://reviews.freebsd.org/D57010

    (cherry picked from commit 6eba055fcf5b0bbfbebcac59f5982d13815001b0)

 sbin/ipfw/ipfw.8                |  3 ++-
 sbin/ipfw/nat.c                 | 29 ++++++++++++++++-------------
 tests/sys/netpfil/common/nat.sh | 26 ++++++++++++++------------
 3 files changed, 32 insertions(+), 26 deletions(-)