Przeglądaj źródła

make /etc/apt/preferences parser deal with comment only sections

Michael Vogt 12 lat temu
rodzic
commit
75ab11ae38

+ 4 - 0
apt-pkg/policy.cc

@@ -405,6 +405,10 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
    PreferenceSection Tags;
    PreferenceSection Tags;
    while (TF.Step(Tags) == true)
    while (TF.Step(Tags) == true)
    {
    {
+      // can happen when there are only comments in a record
+      if (Tags.Count() == 0)
+         continue;
+
       string Name = Tags.FindS("Package");
       string Name = Tags.FindS("Package");
       if (Name.empty() == true)
       if (Name.empty() == true)
 	 return _error->Error(_("Invalid record in the preferences file %s, no Package header"), File.c_str());
 	 return _error->Error(_("Invalid record in the preferences file %s, no Package header"), File.c_str());

+ 9 - 2
apt-pkg/tagfile.cc

@@ -259,7 +259,12 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
    TagCount = 0;
    TagCount = 0;
    while (TagCount+1 < sizeof(Indexes)/sizeof(Indexes[0]) && Stop < End)
    while (TagCount+1 < sizeof(Indexes)/sizeof(Indexes[0]) && Stop < End)
    {
    {
-       TrimRecord(true,End);
+      TrimRecord(true,End);
+
+      // this can happen when TrimRecord trims away the entire Record
+      // (e.g. because it just contains comments)
+      if(Stop == End)
+         return true;
 
 
       // Start a new index and add it to the hash
       // Start a new index and add it to the hash
       if (isspace(Stop[0]) == 0)
       if (isspace(Stop[0]) == 0)
@@ -273,7 +278,9 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
       if (Stop == 0)
       if (Stop == 0)
 	 return false;
 	 return false;
 
 
-      for (; Stop+1 < End && Stop[1] == '\r'; Stop++);
+      for (; Stop+1 < End && Stop[1] == '\r'; Stop++)
+         /* nothing */
+         ;
 
 
       // Double newline marks the end of the record
       // Double newline marks the end of the record
       if (Stop+1 < End && Stop[1] == '\n')
       if (Stop+1 < End && Stop[1] == '\n')

+ 32 - 0
test/integration/test-bug-732746-preferences

@@ -0,0 +1,32 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'i386'
+
+insertinstalledpackage 'bar' 'i386' '1.0'
+
+cat > rootdir/etc/apt/preferences << EOF
+# random test comment header
+
+# commented out by puppy^Wpuppet
+#Package: foo
+#Pin: origin "ftp.debian.org"
+#Pin: 800
+
+Package: bar
+Pin: version 1.0
+Pin-Priority: 700
+
+#Package: bar
+#Pin: version 1.0
+#Pin: 800
+EOF
+
+testequal "Reading package lists...
+Building dependency tree..." aptget check
+
+msgtest "Ensure policy is applied"
+aptcache policy bar|grep -q "*** 1.0 700" && msgpass || msgfail