Bläddra i källkod

s-s-d: Use a heap allocated formatted string for what to stop

Guillem Jover 10 år sedan
förälder
incheckning
6c9dbd427d
2 ändrade filer med 22 tillägg och 11 borttagningar
  1. 4 0
      debian/changelog
  2. 18 11
      utils/start-stop-daemon.c

+ 4 - 0
debian/changelog

@@ -5,6 +5,10 @@ dpkg (1.18.7) UNRELEASED; urgency=medium
     There is no point in erroring out on this condition when signature issues
     are only warnings, because we cannot guarantee we have functional keys
     for old signatures. Regression introduced in dpkg 1.18.5. Closes: #823428
+  * Stop using several fixed sized buffers for program reporting, which in
+    many cases could cause confusing truncation of long messages. Use heap
+    allocated formatted strings instead:
+    - In start-stop-daemon to report what to stop.
   * Perl modules:
     - Relax dependency restrictions parsing to allow again sloppy spaces
       around versions, architectures and profile restrictions.

+ 18 - 11
utils/start-stop-daemon.c

@@ -200,7 +200,7 @@ static char *startas = NULL;
 static pid_t match_pid = -1;
 static pid_t match_ppid = -1;
 static const char *pidfile = NULL;
-static char what_stop[1024];
+static char *what_stop = NULL;
 static const char *progname = "";
 static int nicelevel = 0;
 static int umask_value = -1;
@@ -2159,11 +2159,18 @@ do_stop_summary(int retry_nr)
 	printf(".\n");
 }
 
-static void
-set_what_stop(const char *str)
+static void DPKG_ATTR_PRINTF(1)
+set_what_stop(const char *format, ...)
 {
-	strncpy(what_stop, str, sizeof(what_stop));
-	what_stop[sizeof(what_stop) - 1] = '\0';
+	va_list arglist;
+	int rc;
+
+	va_start(arglist, format);
+	rc = vasprintf(&what_stop, format, arglist);
+	va_end(arglist);
+
+	if (rc < 0)
+		fatal("cannot allocate formatted string");
 }
 
 /*
@@ -2262,17 +2269,17 @@ run_stop_schedule(void)
 	}
 
 	if (cmdname)
-		set_what_stop(cmdname);
+		set_what_stop("%s", cmdname);
 	else if (execname)
-		set_what_stop(execname);
+		set_what_stop("%s", execname);
 	else if (pidfile)
-		sprintf(what_stop, "process in pidfile '%.200s'", pidfile);
+		set_what_stop("process in pidfile '%s'", pidfile);
 	else if (match_pid > 0)
-		sprintf(what_stop, "process with pid %d", match_pid);
+		set_what_stop("process with pid %d", match_pid);
 	else if (match_ppid > 0)
-		sprintf(what_stop, "process(es) with parent pid %d", match_ppid);
+		set_what_stop("process(es) with parent pid %d", match_ppid);
 	else if (userspec)
-		sprintf(what_stop, "process(es) owned by '%.200s'", userspec);
+		set_what_stop("process(es) owned by '%s'", userspec);
 	else
 		fatal("internal error, no match option, please report");