Skip to content

Commit

Permalink
cperl: enforce strict hashpairs in map
Browse files Browse the repository at this point in the history
All @algbyname arrays are already uppercased, skip the uc map there.
See perl11/cperl#281

Also add the svn tags
  • Loading branch information
rurban committed May 14, 2017
1 parent e856615 commit f65acf2
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 87 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MYMETA.json
MYMETA.yml
Makefile
blib/
pm_to_blib
t/IPv6.enabled
t/online.enabled
t/online.nonfatal
29 changes: 28 additions & 1 deletion lib/Net/DNS/RR.pm
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ Resource record time to live in seconds.
# published API. These are required for parsing BIND zone files but
# should not be used in other contexts.
my %unit = ( W => 604800, D => 86400, H => 3600, M => 60, S => 1 );
%unit = ( %unit, map /\D/ ? lc($_) : $_, %unit );
while (my($k,$v) = each %unit) {
$unit{lc($k)} = $v;
}

sub ttl {
my ( $self, $time ) = @_;
Expand Down Expand Up @@ -742,6 +744,31 @@ sub _wrap {
return @line;
}

sub _map_name {
my @args = @_;
my %r;
while (my($arg, $val) = splice @args, 0, 2) {
unless ( $arg =~ /^\d/ ) {
$arg =~ s/[^A-Za-z0-9]//g; # synthetic key
$r{uc $arg} = $val;
}
}
%r
}

sub _map_allow_num {
my @args = @_;
my %r;
while (my($arg, $val) = splice @args, 0, 2) {
unless ( $arg =~ /^\d/ ) {
$arg =~ s/[^A-Za-z0-9]//g; # synthetic key
$r{uc $arg} = $val;
} else {
$r{"$arg"} = $val; # also accept number
}
}
%r
}

################################################################################

Expand Down
12 changes: 1 addition & 11 deletions lib/Net/DNS/RR/CERT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,7 @@ my %certtype = (
);

my %algbyval = reverse @algbyname;

my $map = sub {
my $arg = shift;
unless ( $arg =~ /^\d/ ) {
$arg =~ s/[^A-Za-z0-9]//g; # synthetic key
return uc $arg;
}
my @map = ( $arg, "$arg" => $arg ); # also accept number
};

my %algbyname = map &$map($_), @algbyname;
my %algbyname = Net::DNS::RR::_map_name(@algbyname);

sub _algbyname {
my $arg = shift;
Expand Down
12 changes: 1 addition & 11 deletions lib/Net/DNS/RR/DNSKEY.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,7 @@ use constant BASE64 => defined eval 'require MIME::Base64';
);

my %algbyval = reverse @algbyname;

my $map = sub {
my $arg = shift;
unless ( $arg =~ /^\d/ ) {
$arg =~ s/[^A-Za-z0-9]//g; # synthetic key
return uc $arg;
}
my @map = ( $arg, "$arg" => $arg ); # also accept number
};

my %algbyname = map &$map($_), @algbyname;
my %algbyname = Net::DNS::RR::_map_name(@algbyname);

sub _algbyname {
my $arg = shift;
Expand Down
25 changes: 2 additions & 23 deletions lib/Net/DNS/RR/DS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,7 @@ my %digest = (
);

my %algbyval = reverse @algbyname;

my $map = sub {
my $arg = shift;
unless ( $arg =~ /^\d/ ) {
$arg =~ s/[^A-Za-z0-9]//g; # synthetic key
return uc $arg;
}
my @map = ( $arg, "$arg" => $arg ); # also accept number
};

my %algbyname = map &$map($_), @algbyname;
my %algbyname = @algbyname; # already uppercase

sub _algbyname {
my $arg = shift;
Expand Down Expand Up @@ -108,18 +98,7 @@ my %digest = (
);

my %digestbyval = reverse @digestbyname;

my $map = sub {
my $arg = shift;
unless ( $arg =~ /^\d/ ) {
$arg =~ s/[^A-Za-z0-9]//g; # synthetic key
return uc $arg;
}
my @map = ( $arg, "$arg" => $arg ); # also accept number
};

my %digestbyname = map &$map($_), @digestbyalias, @digestbyname;

my %digestbyname = Net::DNS::RR::_map_name(@digestbyalias, @digestbyname);

sub _digestbyname {
my $arg = shift;
Expand Down
11 changes: 4 additions & 7 deletions lib/Net/DNS/RR/NSEC3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ my %digest = (
'SHA-1' => 1, # RFC3658
);

my @digestbyalias = ( 'SHA' => 1 );

my @digestbyalias = ( 'SHA' => 1,
'SHA1' => 1 ); # internal key
my %digestbyval = reverse @digestbyname;

my @digestbynum = map { ( $_, 0 + $_ ) } keys %digestbyval; # accept algorithm number

my %digestbyname = map { s /[^A-Za-z0-9]//g; $_ } @digestbyalias, @digestbyname, @digestbynum;

my @digestbynum = map { ( "$_", 0 + $_ ) } keys %digestbyval; # accept algorithm number
my %digestbyname = (@digestbyalias, @digestbyname, @digestbynum);

sub _digestbyname {
my $name = shift;
Expand Down
12 changes: 1 addition & 11 deletions lib/Net/DNS/RR/RRSIG.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,7 @@ sub _defaults { ## specify RR attribute default values
);

my %algbyval = reverse @algbyname;

my $map = sub {
my $arg = shift;
unless ( $arg =~ /^\d/ ) {
$arg =~ s/[^A-Za-z0-9]//g; # synthetic key
return uc $arg;
}
my @map = ( $arg, "$arg" => $arg ); # also accept number
};

my %algbyname = map &$map($_), @algbyname;
my %algbyname = Net::DNS::RR::_map_name(@algbyname);

sub _algbyname {
my $arg = shift;
Expand Down
12 changes: 1 addition & 11 deletions lib/Net/DNS/RR/SIG.pm
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,7 @@ sub _defaults { ## specify RR attribute default values
);

my %algbyval = reverse @algbyname;

my $map = sub {
my $arg = shift;
unless ( $arg =~ /^\d/ ) {
$arg =~ s/[^A-Za-z0-9]//g; # synthetic key
return uc $arg;
}
my @map = ( $arg, "$arg" => $arg ); # also accept number
};

my %algbyname = map &$map($_), @algbyname;
my %algbyname = Net::DNS::RR::_map_name(@algbyname);

sub _algbyname {
my $arg = shift;
Expand Down
18 changes: 6 additions & 12 deletions lib/Net/DNS/RR/TSIG.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,10 @@ use constant TSIG => typebyname qw(TSIG);


my %algbyval = reverse @algbyname;

my $map = sub {
my $arg = shift;
return $arg if $arg =~ /^\d/;
$arg =~ s/[^A-Za-z0-9]//g; # strip non-alphanumerics
uc($arg);
};

my @pairedval = sort ( 1 .. 254, 1 .. 254 ); # also accept number
my %algbyname = map &$map($_), @algbyalias, @algbyname, @pairedval;
my %algbyname = Net::DNS::RR::_map_name(@algbyalias, @algbyname);
for (1..254) {
$algbyname{"$_"} = $_; # also accept numbers
}

sub _algbyname {
my $key = uc shift; # synthetic key
Expand Down Expand Up @@ -535,7 +529,7 @@ sub vrfyerrstr {
my $private = shift; # closure keeps private key private
$keyref->{key} = sub {
my $function = $keyref->{digest};
return &$function( $private, @_ );
return &$function( $private, @_ ) if $function;
};
return undef;
}
Expand All @@ -549,7 +543,7 @@ sub vrfyerrstr {
my $keyref = $keytable{$owner};
$keyref->{digest} = $self->sig_function unless $keyref->{digest};
my $function = $keyref->{key};
&$function(@_);
&$function(@_) if $function;
}
}

Expand Down

0 comments on commit f65acf2

Please sign in to comment.