Bläddra i källkod

libdpkg: Trim whitespace from the end of config file lines

This will stop passing strange spaces to the option handlers, and avoids
an unintelligible error message about unbalanced quotes when using quoted
arguments.

Ref: #762031
Reported-by: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
Guillem Jover 11 år sedan
förälder
incheckning
76bfda78aa
2 ändrade filer med 8 tillägg och 4 borttagningar
  1. 2 0
      debian/changelog
  2. 6 4
      lib/dpkg/options.c

+ 2 - 0
debian/changelog

@@ -64,6 +64,8 @@ dpkg (1.18.0) UNRELEASED; urgency=low
     Closes: #776551
     Closes: #776551
   * Move dpkg-divert, dpkg-statoverride and update-alternatives man pages
   * Move dpkg-divert, dpkg-statoverride and update-alternatives man pages
     from section 8 to 1, to match their installation path.
     from section 8 to 1, to match their installation path.
+  * Trim end of line whitespace from dpkg and dselect config file parsers.
+    Reported by Christoph Biedl <debian.axhn@manchmal.in-ulm.de>.
 
 
   [ Updated manpages translations ]
   [ Updated manpages translations ]
   * German (Helge Kreutzmann).
   * German (Helge Kreutzmann).

+ 6 - 4
lib/dpkg/options.c

@@ -87,11 +87,13 @@ dpkg_options_load_file(const char *fn, const struct cmdinfo *cmdinfos)
 
 
     line_num++;
     line_num++;
 
 
-    if ((linebuf[0] == '#') || (linebuf[0] == '\n') || (linebuf[0] == '\0'))
+    l = strlen(linebuf);
+    while (l && c_isspace(linebuf[l - 1]))
+      l--;
+    linebuf[l] = '\0';
+
+    if ((linebuf[0] == '#') || (linebuf[0] == '\0'))
       continue;
       continue;
-    l=strlen(linebuf);
-    if (linebuf[l - 1] == '\n')
-      linebuf[l - 1] = '\0';
     for (opt = linebuf; c_isalnum(*opt) || *opt == '-'; opt++) ;
     for (opt = linebuf; c_isalnum(*opt) || *opt == '-'; opt++) ;
     if (*opt == '\0')
     if (*opt == '\0')
       opt=NULL;
       opt=NULL;