Skip to content

Commit

Permalink
Improve error handling in updatelist.pl
Browse files Browse the repository at this point in the history
- Verifiy if $name is empty
- Enforce $@->stringify if autodie::exception has added a blessed reference to make sure it can be converted to JSON later on
  • Loading branch information
rba committed Mar 22, 2020
1 parent 35308e5 commit 6b8e619
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/updatelist.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use FindBin;
use File::AtomicWrite;
use Data::Dumper;
use Scalar::Util 'blessed';

$|++;

Expand All @@ -31,7 +32,7 @@
my $module = decode_json $response->content;
_normalize_module($module);
my $name = $module->{name};
if ($name =~ m{[/\\]} || $name =~ m{\.\.}) {
if ($name =~ m{[/\\]} || $name =~ m{\.\.} || $name =~ m{^$}) {
die "Invalid module name '$name'";
}
open my $OUT, '>', File::Spec->catfile($OUTDIR, 'module', $name);
Expand All @@ -48,7 +49,7 @@
warn $@;
push @errors, {
url => $url,
message => $@,
message => (blessed $@ eq 'autodie::exception') ? $@->stringify : $@,
};
}
}
Expand Down

0 comments on commit 6b8e619

Please sign in to comment.