Sfoglia il codice sorgente

Check parsed integers for invalid or no digit errors

Verify that the string is not empty or does not contain trailing junk.
Guillem Jover 14 anni fa
parent
commit
157d6447ee
3 ha cambiato i file con 8 aggiunte e 4 eliminazioni
  1. 2 0
      debian/changelog
  2. 4 2
      utils/start-stop-daemon.c
  3. 2 2
      utils/update-alternatives.c

+ 2 - 0
debian/changelog

@@ -22,6 +22,8 @@ dpkg (1.16.4) UNRELEASED; urgency=low
   * Remove obsolete --udeb dpkg-scanpackages option.
   * Remove obsolete --udeb dpkg-scanpackages option.
   * Add arm64 support to cputable. Closes: #672408
   * Add arm64 support to cputable. Closes: #672408
     Thanks Wookey <wookey@wookware.org>.
     Thanks Wookey <wookey@wookware.org>.
+  * Check parsed integers for invalid or no digit errors in start-stop-daemon
+    and update-alternatives.
 
 
   [ Updated man page translations ]
   [ Updated man page translations ]
   * German (Helge Kreutzmann).
   * German (Helge Kreutzmann).

+ 4 - 2
utils/start-stop-daemon.c

@@ -564,12 +564,14 @@ parse_signal(const char *sig_str, int *sig_num)
 static int
 static int
 parse_umask(const char *string, int *value_r)
 parse_umask(const char *string, int *value_r)
 {
 {
+	char *endptr;
+
 	if (!string[0])
 	if (!string[0])
 		return -1;
 		return -1;
 
 
 	errno = 0;
 	errno = 0;
-	*value_r = strtoul(string, NULL, 0);
-	if (errno)
+	*value_r = strtoul(string, &endptr, 0);
+	if (string == endptr || *endptr != '\0' || errno != 0)
 		return -1;
 		return -1;
 	else
 	else
 		return 0;
 		return 0;

+ 2 - 2
utils/update-alternatives.c

@@ -1229,7 +1229,7 @@ alternative_parse_fileset(struct alternative *a, struct altdb_context *ctx)
 		prio_str = altdb_get_line(ctx, _("priority"));
 		prio_str = altdb_get_line(ctx, _("priority"));
 		prio = strtol(prio_str, &prio_end, 10);
 		prio = strtol(prio_str, &prio_end, 10);
 		/* XXX: Leak master_file/prio_str on non-fatal error */
 		/* XXX: Leak master_file/prio_str on non-fatal error */
-		if (*prio_end != '\0')
+		if (prio_str == prio_end || *prio_end != '\0')
 			ctx->bad_format(ctx, _("priority of %s: %s"),
 			ctx->bad_format(ctx, _("priority of %s: %s"),
 			                master_file, prio_str);
 			                master_file, prio_str);
 		fs = fileset_new(master_file, prio);
 		fs = fileset_new(master_file, prio);
@@ -2467,7 +2467,7 @@ main(int argc, char **argv)
 			if (strcmp(argv[i+1], argv[i+3]) == 0)
 			if (strcmp(argv[i+1], argv[i+3]) == 0)
 				badusage(_("<link> and <path> can't be the same"));
 				badusage(_("<link> and <path> can't be the same"));
 			prio = strtol(prio_str, &prio_end, 10);
 			prio = strtol(prio_str, &prio_end, 10);
-			if (*prio_end != '\0')
+			if (prio_str == prio_end || *prio_end != '\0')
 				badusage(_("priority must be an integer"));
 				badusage(_("priority must be an integer"));
 
 
 			a = alternative_new(argv[i + 2]);
 			a = alternative_new(argv[i + 2]);