Browse Source

Fix parsing of or groups in build-deps with ignored packages

If the last alternative(s) of an Or group is ignored, because it does
not match an architecture list, we would end up keeping the or flag,
effectively making the next AND an OR.

For example, when parsing (on amd64):

    debhelper (>= 9), libnacl-dev [amd64] | libnacl-dev [i386]
 => debhelper (>= 9), libnacl-dev |

Which can cause python-apt to crash.

Even worse:

     debhelper (>= 9), libnacl-dev [amd64] | libnacl-dev [i386], foobar
  => debhelper (>= 9), libnacl-dev [amd64] | foobar

By setting the previous alternatives Or flag to the current Or flag
if the current alternative is ignored, we solve the issue.

LP: #1694697
tags/debian/1.4.5
Julian Andres Klode 4 years ago
parent
commit
7ddf958e37
2 changed files with 69 additions and 1 deletions
  1. +11
    -1
      apt-pkg/deb/debsrcrecords.cc
  2. +58
    -0
      test/integration/test-bug-lp1694697-build-dep-architecture-limited-alternative

+ 11
- 1
apt-pkg/deb/debsrcrecords.cc View File

@@ -129,8 +129,18 @@ bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDe
return _error->Error("Problem parsing dependency: %s", fields[I]);
rec.Type = I;

if (rec.Package != "")
// We parsed a package that was ignored (wrong architecture restriction
// or something).
if (rec.Package == "") {
// If we are in an OR group, we need to set the "Or" flag of the
// previous entry to our value.
if (BuildDeps.size() > 0 && (BuildDeps[BuildDeps.size() - 1].Op & pkgCache::Dep::Or) == pkgCache::Dep::Or) {
BuildDeps[BuildDeps.size() - 1].Op &= ~pkgCache::Dep::Or;
BuildDeps[BuildDeps.size() - 1].Op |= (rec.Op & pkgCache::Dep::Or);
}
} else {
BuildDeps.push_back(rec);
}
if (Start == Stop)
break;


+ 58
- 0
test/integration/test-bug-lp1694697-build-dep-architecture-limited-alternative View File

@@ -0,0 +1,58 @@
#!/bin/sh
set -e

TESTDIR="$(readlink -f "$(dirname "$0")")"
. "$TESTDIR/framework"

setupenvironment
configarchitecture 'i386'


insertpackage 'stable' 'build-depends' 'i386' '1'
insertpackage 'stable' 'foo' 'i386' '1'
insertinstalledpackage 'build-essential' 'i386' '1'

setupaptarchive

# This used to be interpreted as build-depends | foo
cat > foobar.dsc <<EOF
Format: 3.0 (native)
Source: foobar
Binary: foobar
Architecture: all
Version: 1
Maintainer: Joe Sixpack <joe@example.org>
Build-Depends: build-depends [i386] | build-depends [amd64], foo
Standards-Version: 3.9.8
EOF
testsuccessequal "Note, using file './foobar.dsc' to get the build dependencies
Reading package lists...
Building dependency tree...
The following NEW packages will be installed:
build-depends foo
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Inst build-depends (1 stable [i386])
Inst foo (1 stable [i386])
Conf build-depends (1 stable [i386])
Conf foo (1 stable [i386])" aptget build-dep --simulate ./foobar.dsc


# This caused a segmentation fault
cat > foobar.dsc <<EOF
Format: 3.0 (native)
Source: foobar
Binary: foobar
Architecture: all
Version: 1
Maintainer: Joe Sixpack <joe@example.org>
Build-Depends: build-depends [i386] | build-depends [amd64]
Standards-Version: 3.9.8
EOF
testsuccessequal "Note, using file './foobar.dsc' to get the build dependencies
Reading package lists...
Building dependency tree...
The following NEW packages will be installed:
build-depends
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Inst build-depends (1 stable [i386])
Conf build-depends (1 stable [i386])" aptget build-dep --simulate ./foobar.dsc

Loading…
Cancel
Save