From 02791991cab3889b6a002907fa4f113a470b7838 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Mon, 8 Nov 2010 14:21:58 -0800 Subject: Add check for valid integer. --- scripts/vyatta-config-mgmt.pl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-config-mgmt.pl b/scripts/vyatta-config-mgmt.pl index c616fdb..a6bac48 100755 --- a/scripts/vyatta-config-mgmt.pl +++ b/scripts/vyatta-config-mgmt.pl @@ -55,9 +55,20 @@ sub get_link { return $link; } +sub check_integer { + my ($num) = @_; + + if ($num !~ /^\d+$/) { + print "Invalid number [$num]\n"; + exit 1; + } + return 1; +} + sub check_valid_rev { my ($rev) = @_; + check_integer($rev); my $num_revs = cm_get_num_revs(); return 1 if $rev <= $num_revs; print "Invalid revision [$rev]\n"; @@ -72,8 +83,8 @@ my ($action, $uri, $revs, $revnum); Getopt::Long::Configure('pass_through'); GetOptions("action=s" => \$action, "uri=s" => \$uri, - "revs=i" => \$revs, - "revnum=i" => \$revnum, + "revs=s" => \$revs, + "revnum=s" => \$revnum, ); die "Error: no action" if ! defined $action; @@ -131,6 +142,7 @@ if ($action eq 'valid-uri') { if ($action eq 'update-revs') { die "Error: no revs" if ! defined $revs; print "update-revs [$revs]\n" if $debug; + check_integer($revs); my $link = get_link($commit_revs_script); if ($revs == 0) { print "remove link [$link]\n" if $debug; @@ -185,6 +197,7 @@ if ($action eq 'show-commit-file') { check_valid_rev($revnum); my $file = cm_commit_get_file($revnum); print $file; + exit 0; } if ($action eq 'diff') { @@ -215,6 +228,7 @@ if ($action eq 'diff') { my $diff = `zdiff -u $filename2 $filename`; print $diff; } + exit 0; } exit $rc; -- cgit v1.2.3