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

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 година
родитељ
комит
157d6447ee
3 измењених фајлова са 8 додато и 4 уклоњено
  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.
   * Add arm64 support to cputable. Closes: #672408
     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 ]
   * 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
 parse_umask(const char *string, int *value_r)
 {
+	char *endptr;
+
 	if (!string[0])
 		return -1;
 
 	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;
 	else
 		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 = strtol(prio_str, &prio_end, 10);
 		/* 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"),
 			                master_file, prio_str);
 		fs = fileset_new(master_file, prio);
@@ -2467,7 +2467,7 @@ main(int argc, char **argv)
 			if (strcmp(argv[i+1], argv[i+3]) == 0)
 				badusage(_("<link> and <path> can't be the same"));
 			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"));
 
 			a = alternative_new(argv[i + 2]);