]> git.saurik.com Git - apt.git/commitdiff
make /etc/apt/preferences parser deal with comment only sections
authorMichael Vogt <mvo@debian.org>
Sat, 21 Dec 2013 17:50:03 +0000 (18:50 +0100)
committerMichael Vogt <mvo@debian.org>
Sat, 21 Dec 2013 18:09:06 +0000 (19:09 +0100)
apt-pkg/policy.cc
apt-pkg/tagfile.cc
test/integration/test-bug-732746-preferences [new file with mode: 0755]

index 0a06cc6e3d769f7b072f81144daff2d586dd96dc..d0f97441d878318bcb7a540324c3c8cdde6ce0fd 100644 (file)
@@ -405,6 +405,10 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
    PreferenceSection Tags;
    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");
       if (Name.empty() == true)
         return _error->Error(_("Invalid record in the preferences file %s, no Package header"), File.c_str());
index e0802e3d547e67666035e7d23409428fcca91b1c..bef3c76ba3c92c8c5c98e1342902109880f3bcac 100644 (file)
@@ -259,7 +259,12 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
    TagCount = 0;
    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
       if (isspace(Stop[0]) == 0)
@@ -273,7 +278,9 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
       if (Stop == 0)
         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
       if (Stop+1 < End && Stop[1] == '\n')
diff --git a/test/integration/test-bug-732746-preferences b/test/integration/test-bug-732746-preferences
new file mode 100755 (executable)
index 0000000..b31f98a
--- /dev/null
@@ -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