Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipaddress.IPv4Network allows prefix > 32 #80170

Open
JohnFlorian mannequin opened this issue Feb 13, 2019 · 7 comments
Open

ipaddress.IPv4Network allows prefix > 32 #80170

JohnFlorian mannequin opened this issue Feb 13, 2019 · 7 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@JohnFlorian
Copy link
Mannequin

JohnFlorian mannequin commented Feb 13, 2019

BPO 35989
Nosy @pitrou, @matrixise, @jheiv, @remilapeyre, @tirkarthi
PRs
  • bpo-35989: Forbid a netmask > 32 for ipaddress.IPv4Network #11844
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2019-02-13.16:13:55.267>
    labels = ['3.7', 'type-bug', 'library']
    title = 'ipaddress.IPv4Network allows prefix > 32'
    updated_at = <Date 2019-05-18.12:19:37.025>
    user = 'https://bugs.python.org/JohnFlorian'

    bugs.python.org fields:

    activity = <Date 2019-05-18.12:19:37.025>
    actor = 'xtreak'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-02-13.16:13:55.267>
    creator = 'John Florian'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35989
    keywords = ['patch']
    message_count = 5.0
    messages = ['335460', '335475', '337228', '337230', '342795']
    nosy_count = 6.0
    nosy_names = ['pitrou', 'matrixise', 'jedwards', 'John Florian', 'remi.lapeyre', 'xtreak']
    pr_nums = ['11844']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue35989'
    versions = ['Python 3.7']

    @JohnFlorian
    Copy link
    Mannequin Author

    JohnFlorian mannequin commented Feb 13, 2019

    I wanted a simple is_valid_ipv4_network() function, so I wrote one and a bunch of unit tests where I discovered that I can legally:

    >>> n = IPv4Network(('192.168.123.234', 12345678))
    >>> n
    IPv4Network('192.168.123.234/12345678')
    >>> n.prefixlen
    12345678
    >>> n.max_prefixlen
    32

    I assume this is a bug.

    @JohnFlorian JohnFlorian mannequin added the 3.7 (EOL) end of life label Feb 13, 2019
    @SilentGhost SilentGhost mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 13, 2019
    @matrixise
    Copy link
    Member

    I proposed my PR but I prefer a review because in the code of ipaddress, there is a function for the validation of an address with the netmask. Maybe we could use this function and try to refactor/improve the current code.

    @remilapeyre
    Copy link
    Mannequin

    remilapeyre mannequin commented Mar 5, 2019

    Hi @maxtrixise, thanks for PR,

    there is a function for the validation of an address with the netmask

    Which one do you want to use?

    @jheiv
    Copy link
    Mannequin

    jheiv mannequin commented Mar 5, 2019

    It may be worth also addressing the fact that IPv6Network makes no restriction on it's netmask (when specified as a tuple).

    @tirkarthi
    Copy link
    Member

    See also bpo-36845 that seems to have fixed this.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @furkanonder
    Copy link
    Contributor

    See also bpo-36845 that seems to have fixed this.

    Yes, the issue seems to be solved. I think we can close the issue.

    >>> from ipaddress import IPv4Network
    >>> n = IPv4Network(('192.168.123.234', 12345678))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.11/ipaddress.py", line 1513, in __init__
        self.netmask, self._prefixlen = self._make_netmask(mask)
                                        ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/ipaddress.py", line 1170, in _make_netmask
        cls._report_invalid_netmask(prefixlen)
      File "/usr/lib/python3.11/ipaddress.py", line 472, in _report_invalid_netmask
        raise NetmaskValueError(msg) from None
    ipaddress.NetmaskValueError: 12345678 is not a valid netmask
    >>> 
    

    @devdanzin
    Copy link
    Contributor

    Seems completely fixed by #13298.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants