summaryrefslogtreecommitdiff
path: root/FS/FS/Record.pm
diff options
context:
space:
mode:
authorMitch Jackson <mitch@freeside.biz>2018-10-22 22:56:04 -0400
committerMitch Jackson <mitch@freeside.biz>2018-10-22 23:01:47 -0400
commited72ea9bc6909be8dfaa317eb4e5681702d6fb4f (patch)
tree85ca8bad2d4d30f315dbf20305af6fdfe2740074 /FS/FS/Record.pm
parenta7d14a749e808369e22aa1b0026af5bc74225961 (diff)
RT# 80555 Clean up code removing leading 0's from ip addr input
Diffstat (limited to 'FS/FS/Record.pm')
-rw-r--r--FS/FS/Record.pm30
1 files changed, 18 insertions, 12 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 2a4a200..60e7ff7 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -2912,18 +2912,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 '';
}
@@ -2943,6 +2934,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.