Browse Source

dpkg-query: fix segfault when -f parameter is empty

Giving an empty parameter seems pretty useless, but it can also be
the result of user errors like using “-f "${Package}"” instead
of “-f '${Package}'” and the segfault does not really help to
understand one's fault.

This commit fixes pkg_format_parse() to define the error message
when the function had nothing to parse. It already returned
the appropriate NULL value but the fact that the error message
was uninitialized resulted in the segfault.
Raphaël Hertzog 14 years ago
parent
commit
9a06920db6
2 changed files with 4 additions and 0 deletions
  1. 1 0
      debian/changelog
  2. 3 0
      lib/dpkg/pkg-format.c

+ 1 - 0
debian/changelog

@@ -3,6 +3,7 @@ dpkg (1.16.9) UNRELEASED; urgency=low
   [ Raphaël Hertzog ]
   * Fix dpkg-source regression in "3.0 (quilt)" source packages while
     unapplying patches that remove all files in a directory. Closes: #683547
+  * Fix segfault of “dpkg-query -W -f ''”.
 
   [ Updated programs translations ]
   * Czech (Miroslav Kure).

+ 3 - 0
lib/dpkg/pkg-format.c

@@ -208,6 +208,9 @@ pkg_format_parse(const char *fmt, struct dpkg_error *err)
 		}
 	}
 
+	if (!head)
+		dpkg_put_error(err, _("may not be empty string"));
+
 	return head;
 }