Преглед изворни кода

Fix preinst to not fail on read on broken alternatives status files

The internal structure of alternatives status file is line based.
Empty lines end each section. read call can fail if the file is truncated
at some unexpected point. Thus protect all read calls with "|| continue"
or "|| break" depending on the case.
Raphael Hertzog пре 17 година
родитељ
комит
b866c02dfc
2 измењених фајлова са 6 додато и 4 уклоњено
  1. 2 0
      debian/changelog
  2. 4 4
      debian/dpkg.preinst

+ 2 - 0
debian/changelog

@@ -32,6 +32,8 @@ dpkg (1.15.4) UNRELEASED; urgency=low
     See http://wiki.debian.org/Transitions/DpkgToGnuInstallInfo for details.
     See http://wiki.debian.org/Transitions/DpkgToGnuInstallInfo for details.
   * Fix dpkg's preinst in case /var/lib/dpkg/alternatives contains unexpected
   * Fix dpkg's preinst in case /var/lib/dpkg/alternatives contains unexpected
     sub-directories. Closes: #535138
     sub-directories. Closes: #535138
+    And also when one of the file doesn't contain correct alternatives
+    information (improper number of lines). Closes: #537558
   * Upgrade Standards-Version to 3.8.2 (no changes).
   * Upgrade Standards-Version to 3.8.2 (no changes).
   * Update deb-substvars(5) to list fields that do not support substvars.
   * Update deb-substvars(5) to list fields that do not support substvars.
     Closes: #535353
     Closes: #535353

+ 4 - 4
debian/dpkg.preinst

@@ -36,10 +36,10 @@ kill_bad_alternatives () {
             continue
             continue
         fi
         fi
         {
         {
-            read mode
-            read mainlink
+            read mode || continue
+            read mainlink || continue
             while true; do
             while true; do
-                read slave
+                read slave || break
                 if [ "$slave" = "" ]; then
                 if [ "$slave" = "" ]; then
                     break
                     break
                 fi
                 fi
@@ -47,7 +47,7 @@ kill_bad_alternatives () {
                     echo "Removing conflicting master alternative $slave (it is slave of $(basename $alt))..."
                     echo "Removing conflicting master alternative $slave (it is slave of $(basename $alt))..."
                     rm -f "$ALTDIR/$slave"
                     rm -f "$ALTDIR/$slave"
                 fi
                 fi
-                read slavelink
+                read slavelink || break
             done
             done
         } <$alt
         } <$alt
     done
     done