Skip to content

Commit

Permalink
[backend] guard against parser crashes
Browse files Browse the repository at this point in the history
Parers should guard against crashes themselfes, but better save
than sorry...

Also make repository parsing more robust against extra data.
  • Loading branch information
mlschroe committed Jun 1, 2017
1 parent 2db9c73 commit 1518127
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/backend/bs_srcserver
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ $BSSrcServer::Product::notify_repservers = \&notify_repservers;

$Build::Rpm::unfilteredprereqs = 1 if defined $Build::Rpm::unfilteredprereqs;
$Build::Rpm::conflictdeps = 1 if defined $Build::Rpm::conflictdeps;
$Build::Kiwi::repopriorities = 1 if defined $Build::Kiwi::repopriorities;
$Build::Kiwi::repoextras = 1 if defined $Build::Kiwi::repoextras;

use strict;

Expand Down Expand Up @@ -1570,7 +1570,14 @@ sub getprojpack {
$conf->{'obspackage'} = $1;
$conf->{'buildflavor'} = $2;
}
my $d = Build::parse_typed($conf, BSRevision::revfilename($rev, $file, $files->{$file}), $buildtype);
my $d;
eval {
$d = Build::parse_typed($conf, BSRevision::revfilename($rev, $file, $files->{$file}), $buildtype);
};
if ($@) {
$d = {'error' => $@};
$d->{'error'} =~ s/\n.*//s;
}
data2utf8xml($d);

if (!$d || !defined($d->{'name'})) {
Expand Down Expand Up @@ -1618,6 +1625,11 @@ sub getprojpack {
for ('imagetype', 'path', 'extrasource') {
$rinfo->{$_} = $d->{$_} if exists $d->{$_};
}
for (@{$d->{'path'} || []}) {
my $r = { 'project' => $_->{'project'}, 'repository' => $_->{'repository'} };
$r->{'priority'} = $_->{'priority'} if defined $_->{'priority'};
push @{$r->{'path'}}, $r;
}
if ($remotemap && $rinfo->{'path'}) {
my @kiwipath = map {"$_->{'project'}/$_->{'repository'}"} grep {$_->{'project'} ne '_obsrepositories'} @{$rinfo->{'path'}};
# simple way to fill the remote map
Expand Down Expand Up @@ -5526,9 +5538,17 @@ sub sourceinfo {
$bconf->{'buildflavor'} = $2;
}

my $d = Build::parse_typed($bconf, BSRevision::revfilename($rev, $file, $files->{$file}), $buildtype);
my $d;
eval {
$d = Build::parse_typed($bconf, BSRevision::revfilename($rev, $file, $files->{$file}), $buildtype);
};
if ($@) {
$r->{'error'} = "parse error: $@";
$r->{'error'} =~ s/\n.*//s;
return $r;
}
if (!$d) {
$r->{'error'} = "parse error";
$r->{'error'} = 'parse error';
return $r;
}
for (qw{name version release subpacks deps prereqs exclarch badarch}) {
Expand Down

0 comments on commit 1518127

Please sign in to comment.