timmerk / ipaddr-py

Automatically exported from code.google.com/p/ipaddr-py
0 stars 0 forks source link

When printing an error message about collapsing v4 and v6 addresses together, an IndexError excpetion fires instead #95

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

ipaddr.CollapseAddrList([ipaddr.IPNetwork('10/8'), 
ipaddr.IPNetwork('2001:DB8::/32')])

Traceback (most recent call last):
 File "ipaddr/__init__.py", line 353, in collapse_address_list
IndexError: list index out of range

What is the expected output? What do you see instead?

Should be an error about incompatibility between two address types or something 
like that.

Please provide any additional information below.

In the following code it looks like line 353 was copied verbatim from line 348, 
when it should have been changed to refer to nets.

 338:     # split IP addresses and networks
 339:     for ip in addresses:
 340:         if isinstance(ip, _BaseIP):
 341:             if ips and ips[-1]._version != ip._version:
 342:                 raise TypeError("%s and %s are not of the same version" % (
 343:                         str(ip), str(ips[-1])))
 344:             ips.append(ip)
 345:         elif ip._prefixlen == ip._max_prefixlen:
 346:             if ips and ips[-1]._version != ip._version:
 347:                 raise TypeError("%s and %s are not of the same version" % (
 348:                         str(ip), str(ips[-1])))
 349:             ips.append(ip.ip)
 350:         else:
 351:             if nets and nets[-1]._version != ip._version:
 352:                 raise TypeError("%s and %s are not of the same version" % (
 353:                         str(ip), str(ips[-1])))
 354:             nets.append(ip)

Original issue reported on code.google.com by ke...@google.com on 18 May 2012 at 9:30

GoogleCodeExporter commented 9 years ago
fixed in ba2b1c9.
thanks for the report.

Original comment by pmo...@google.com on 11 Jun 2012 at 4:40