From f9bda7d0a0f89e4f53d2e41ff1bd6b7b1d27634e Mon Sep 17 00:00:00 2001 From: teastep Date: Fri, 7 Dec 2007 19:06:01 +0000 Subject: [PATCH] Eliminate one version of numeric_value() git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@7856 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb --- Shorewall-perl/Shorewall/Chains.pm | 2 +- Shorewall-perl/Shorewall/Compiler.pm | 8 ++++---- Shorewall-perl/Shorewall/Config.pm | 19 ++++--------------- Shorewall-perl/Shorewall/Policy.pm | 6 +++--- Shorewall-perl/Shorewall/Providers.pm | 8 +++++++- Shorewall-perl/Shorewall/Rules.pm | 11 ++++++----- Shorewall-perl/Shorewall/Zones.pm | 4 +++- 7 files changed, 28 insertions(+), 30 deletions(-) diff --git a/Shorewall-perl/Shorewall/Chains.pm b/Shorewall-perl/Shorewall/Chains.pm index 56dc9c357..286ce636a 100644 --- a/Shorewall-perl/Shorewall/Chains.pm +++ b/Shorewall-perl/Shorewall/Chains.pm @@ -1113,7 +1113,7 @@ sub verify_mark( $ ) { my $value = numeric_value( $mark ); fatal_error "Invalid Mark or Mask value ($mark)" - unless $value <= $limit; + unless defined( $value ) && $value <= $limit; fatal_error "Invalid High Mark or Mask value ($mark)" if ( $value > 0xFF && $value & 0xFF ); diff --git a/Shorewall-perl/Shorewall/Compiler.pm b/Shorewall-perl/Shorewall/Compiler.pm index d0766a8b2..ff9622f82 100644 --- a/Shorewall-perl/Shorewall/Compiler.pm +++ b/Shorewall-perl/Shorewall/Compiler.pm @@ -708,13 +708,13 @@ sub compiler { $export = 0; sub edit_boolean( $ ) { - my $val = numeric_value1( shift ); - defined $val && $val >= 0 && $val < 2; + my $val = numeric_value( shift ); + defined($val) && ($val >= 0) && ($val < 2); } sub edit_verbosity( $ ) { - my $val = numeric_value1( shift ); - defined $val && $val >= -1 && $val < 3; + my $val = numeric_value( shift ); + defined($val) && ($val >= -1) && ($val < 3); } my %elbat = ( object => { store => \$objectfile }, diff --git a/Shorewall-perl/Shorewall/Config.pm b/Shorewall-perl/Shorewall/Config.pm index cb9f02e0c..3a95ee2dd 100644 --- a/Shorewall-perl/Shorewall/Config.pm +++ b/Shorewall-perl/Shorewall/Config.pm @@ -55,7 +55,6 @@ our @EXPORT_OK = qw( $shorewall_dir initialize read_a_line1 set_config_path shor our %EXPORT_TAGS = ( internal => [ qw( create_temp_object finalize_object numeric_value - numeric_value1 emit emit_unindented save_progress_message @@ -506,12 +505,6 @@ sub fatal_error1 { # Convert value to decimal number # sub numeric_value ( $ ) { - my $mark = lc $_[0]; - fatal_error "Invalid Numeric Value ($mark)" unless $mark =~ /^-?(0x[a-f0-9]+|0[0-7]*|[1-9]\d*)$/; - $mark =~ /^0/ ? oct $mark : $mark; -} - -sub numeric_value1 ( $ ) { my $mark = lc $_[0]; return undef unless $mark =~ /^-?(0x[a-f0-9]+|0[0-7]*|[1-9]\d*)$/; $mark =~ /^0/ ? oct $mark : $mark; @@ -586,18 +579,14 @@ sub set_log ( $$ ) { if ( defined $v ) { my $value = numeric_value( $v ); - - if ( ( $value < -1 ) || ( $value > 2 ) ) { - fatal_error "Invalid Log Verbosity ( $v )"; - } - + fatal_error "Invalid Log Verbosity ( $v )" unless defined($value) && ( $value >= -1 ) && ( $value <= 2); $log_verbose = $value; } if ( $l && $log_verbose >= 0 ) { unless ( open $log , '>>' , $l ) { $log = undef; - fatal_error "Unable to open $l for writing: $!"; + fatal_error "Unable to open STARTUP_LOG ($l) for writing: $!"; } } else { $log_verbose = -1; @@ -1799,8 +1788,8 @@ sub get_configuration( $ ) { if ( $config{LOG_VERBOSITY} eq '' ) { $config{LOG_VERBOSITY} = 2; } else { - my $val = numeric_value1( $config{LOG_VERBOSITY} ); - fatal_error "Invalid LOG_VERBOSITY ($config{LOG_VERBOSITY} )" unless defined $val && $val >= -1 && $val <= 2; + my $val = numeric_value( $config{LOG_VERBOSITY} ); + fatal_error "Invalid LOG_VERBOSITY ($config{LOG_VERBOSITY} )" unless defined( $val ) && ( $val >= -1 ) && ( $val <= 2 ); $config{STARTUP_LOG} = '' if $config{LOG_VERBOSITY} < 0; } } else { diff --git a/Shorewall-perl/Shorewall/Policy.pm b/Shorewall-perl/Shorewall/Policy.pm index 72cff9896..8d7fa4080 100644 --- a/Shorewall-perl/Shorewall/Policy.pm +++ b/Shorewall-perl/Shorewall/Policy.pm @@ -254,9 +254,9 @@ sub validate_policy() if ( defined $queue ) { fatal_error "Invalid policy ($policy/$queue)" unless $policy eq 'NFQUEUE'; require_capability( 'NFQUEUE_TARGET', 'An NFQUEUE Policy', 's' ); - $queue = numeric_value( $queue ); - fatal_error "Invalid NFQUEUE queue number ($queue)" if $queue > 65535; - $policy = "NFQUEUE --queue-num $queue"; + my $queuenum = numeric_value( $queue ); + fatal_error "Invalid NFQUEUE queue number ($queue)" unless defined( $queuenum) && $queuenum <= 65535; + $policy = "NFQUEUE --queue-num $queuenum"; } elsif ( $policy eq 'NONE' ) { fatal_error "NONE policy not allowed with \"all\"" if $clientwild || $serverwild; diff --git a/Shorewall-perl/Shorewall/Providers.pm b/Shorewall-perl/Shorewall/Providers.pm index 4b995accf..e330eef3a 100644 --- a/Shorewall-perl/Shorewall/Providers.pm +++ b/Shorewall-perl/Shorewall/Providers.pm @@ -192,7 +192,11 @@ sub add_a_provider( $$$$$$$$ ) { fatal_error "Duplicate provider ($table)" if $providers{$table}; - $number = numeric_value $number; + my $num = numeric_value $number; + + fatal_error "Invalid Provider number ($number)" unless defined $num; + + $number = $num; for my $providerref ( values %providers ) { fatal_error "Duplicate provider number ($number)" if $providerref->{number} == $number; @@ -238,6 +242,8 @@ sub add_a_provider( $$$$$$$$ ) { $val = numeric_value $mark; + fatal_error "Invalid Mark Value ($mark)" unless defined $val; + verify_mark $mark; if ( $val < 256) { diff --git a/Shorewall-perl/Shorewall/Rules.pm b/Shorewall-perl/Shorewall/Rules.pm index a7bca6dd7..eca215faf 100644 --- a/Shorewall-perl/Shorewall/Rules.pm +++ b/Shorewall-perl/Shorewall/Rules.pm @@ -110,8 +110,9 @@ sub process_tos() { if ( defined ( my $tosval = $tosoptions{"\L$tos"} ) ) { $tos = $tosval; - } elsif ( numeric_value( $tos ) > 0x1e ) { - fatal_error "Invalid TOS value ($tos)"; + } else { + my $val = numeric_value( $tos ); + fatal_error "Invalid TOS value ($tos)" unless defined( $val ) && $val < 0x1f; } my $chainref; @@ -954,9 +955,9 @@ sub process_rule1 ( $$$$$$$$$$$ ) { } elsif ( $actiontype & NFQ ) { require_capability( 'NFQUEUE_TARGET', 'NFQUEUE Rules', '' ); - $param = $param eq '' ? 0 : numeric_value( $param ); - fatal_error "Invalid value ($param) for NFQUEUE queue number" if $param > 65535; - $action = "NFQUEUE --queue-num $param"; + my $paramval = $param eq '' ? 0 : numeric_value( $param ); + fatal_error "Invalid value ($param) for NFQUEUE queue number" unless defined($paramval) && $paramval <= 65535; + $action = "NFQUEUE --queue-num $paramval"; } else { fatal_error "The $basictarget TARGET does not accept a parameter" unless $param eq ''; } diff --git a/Shorewall-perl/Shorewall/Zones.pm b/Shorewall-perl/Shorewall/Zones.pm index 477b2edff..f5f4de596 100644 --- a/Shorewall-perl/Shorewall/Zones.pm +++ b/Shorewall-perl/Shorewall/Zones.pm @@ -700,7 +700,9 @@ sub validate_interfaces_file( $ ) } } elsif ( $type == NUMERIC_IF_OPTION ) { fatal_error "The $option option requires a value" unless defined $value; - $options{$option} = numeric_value $value; + my $numval = numeric_value $value; + fatal_error "Invalid value for option $option ($value)" unless defined $numval; + $options{$option} = $numval; } else { warning_message "Support for the $option interface option has been removed from Shorewall-perl"; }