[freeside-commits] branch master updated. ae40f1d7aa1a0fcf8c32c60660a51de3551854d8
Mitch Jackson
mitch at freeside.biz
Mon Oct 22 19:59:43 PDT 2018
The branch, master has been updated
via ae40f1d7aa1a0fcf8c32c60660a51de3551854d8 (commit)
from ccc850e9ace238da093cd13dc3fd833629fcf47a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ae40f1d7aa1a0fcf8c32c60660a51de3551854d8
Author: Mitch Jackson <mitch at freeside.biz>
Date: Mon Oct 22 22:56:04 2018 -0400
RT# 80555 Clean up code removing leading 0's from ip addr input
diff --git a/FS/FS/IP_Mixin.pm b/FS/FS/IP_Mixin.pm
index fc3a0146b..1967ccd57 100644
--- a/FS/FS/IP_Mixin.pm
+++ b/FS/FS/IP_Mixin.pm
@@ -94,14 +94,9 @@ sub ip_check {
$self->ip_addr('');
}
- # strip user-entered leading 0's from IPv4 addresses
- # Parsers like NetAddr::IP interpret them as octal instead of decimal
- $self->ip_addr(
- join( '.', (
- map{ int($_) }
- split( /\./, $self->ip_addr )
- ))
- ) if $self->ip_addr =~ /\./ && $self->ip_addr =~ /[\.^]0/;
+ # Will strip extraneous leading zeros from ip adddresses
+ # e.g. 10.0.022.220 corrected to 10.0.22.220
+ $self->ut_ip46n('ip_addr');
if ( $self->ip_addr
and !$self->router
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 97a60b777..9eb1c9aeb 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -2916,18 +2916,9 @@ Check/untaint IPv4 or IPv6 address.
sub ut_ip46 {
my( $self, $field ) = @_;
- my $ip_addr = $self->getfield( $field );
-
- # strip user-entered leading 0's from IPv4 addresses
- # Parsers like NetAddr::IP interpret them as octal instead of decimal
- $ip_addr = join( '.', (
- map{ int($_) }
- split( /\./, $ip_addr )
- )
- ) if $ip_addr =~ /\./ && $ip_addr =~ /[\.^]0/;
-
- my $ip = NetAddr::IP->new( $ip_addr )
- or return "Illegal (IP address) $field: ".$self->getfield($field);
+ my $ip = NetAddr::IP->new(
+ $self->_ut_ip_strip_leading_zeros( $self->getfield( $field ) )
+ ) or return "Illegal (IP address) $field: ".$self->getfield($field);
$self->setfield($field, lc($ip->addr));
return '';
}
@@ -2947,6 +2938,21 @@ sub ut_ip46n {
$self->ut_ip46($field);
}
+sub _ut_ip_strip_leading_zeros {
+ # strip user-entered leading 0's from IP addresses
+ # so parsers like NetAddr::IP don't mangle the address
+ # e.g. NetAddr::IP converts 10.0.022.220 into 10.0.18.220
+
+ my ( $self, $ip ) = @_;
+
+ return join '.', map int, split /\./, $ip
+ if $ip
+ && $ip =~ /\./
+ && $ip =~ /[\.^]0/;
+ $ip;
+}
+
+
=item ut_coord COLUMN [ LOWER [ UPPER ] ]
Check/untaint coordinates.
-----------------------------------------------------------------------
Summary of changes:
FS/FS/IP_Mixin.pm | 11 +++--------
FS/FS/Record.pm | 30 ++++++++++++++++++------------
2 files changed, 21 insertions(+), 20 deletions(-)
More information about the freeside-commits
mailing list