Prechádzať zdrojové kódy

libdpkg: Handle space-only strings when parsing versions

Consider these empty strings too.
Guillem Jover 12 rokov pred
rodič
commit
1a27a761f5
3 zmenil súbory, kde vykonal 8 pridanie a 4 odobranie
  1. 1 0
      debian/changelog
  2. 4 3
      lib/dpkg/parsehelp.c
  3. 3 1
      lib/dpkg/test/t-version.c

+ 1 - 0
debian/changelog

@@ -5,6 +5,7 @@ dpkg (1.17.8) UNRELEASED; urgency=low
   * Test suite:
   * Test suite:
     - Improve Perl code coverage.
     - Improve Perl code coverage.
     - Improve C code coverage.
     - Improve C code coverage.
+  * Handle space-only strings when parsing versions in libdpkg.
 
 
  -- Guillem Jover <guillem@debian.org>  Mon, 21 Apr 2014 17:59:10 +0200
  -- Guillem Jover <guillem@debian.org>  Mon, 21 Apr 2014 17:59:10 +0200
 
 

+ 4 - 3
lib/dpkg/parsehelp.c

@@ -213,12 +213,13 @@ parseversion(struct dpkg_version *rversion, const char *string,
   char *hyphen, *colon, *eepochcolon;
   char *hyphen, *colon, *eepochcolon;
   const char *end, *ptr;
   const char *end, *ptr;
 
 
-  if (!*string)
-    return dpkg_put_error(err, _("version string is empty"));
-
   /* Trim leading and trailing space. */
   /* Trim leading and trailing space. */
   while (*string && isblank(*string))
   while (*string && isblank(*string))
     string++;
     string++;
+
+  if (!*string)
+    return dpkg_put_error(err, _("version string is empty"));
+
   /* String now points to the first non-whitespace char. */
   /* String now points to the first non-whitespace char. */
   end = string;
   end = string;
   /* Find either the end of the string, or a whitespace char. */
   /* Find either the end of the string, or a whitespace char. */

+ 3 - 1
lib/dpkg/test/t-version.c

@@ -246,6 +246,8 @@ test_version_parse(void)
 	/* Test empty version. */
 	/* Test empty version. */
 	test_pass(parseversion(&a, "", &err) != 0);
 	test_pass(parseversion(&a, "", &err) != 0);
 	test_error(err);
 	test_error(err);
+	test_pass(parseversion(&a, "  ", &err) != 0);
+	test_error(err);
 
 
 	/* Test empty upstream version after epoch. */
 	/* Test empty upstream version after epoch. */
 	test_fail(parseversion(&a, "0:", &err) == 0);
 	test_fail(parseversion(&a, "0:", &err) == 0);
@@ -300,7 +302,7 @@ test_version_parse(void)
 static void
 static void
 test(void)
 test(void)
 {
 {
-	test_plan(188);
+	test_plan(190);
 
 
 	test_version_blank();
 	test_version_blank();
 	test_version_is_informative();
 	test_version_is_informative();