diff options
author | Guillem Jover <guillem@debian.org> | 2016-05-06 01:15:38 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2016-05-09 03:40:03 +0200 |
commit | 6c9dbd427d085ce0bba878e294d1c8c20d1112cd (patch) | |
tree | b80be45646894ecf30150fac8534306ac7cdd5f8 /utils | |
parent | a558a21ae7f04751f7f5dfe724cd9d5f95905734 (diff) | |
download | dpkg-6c9dbd427d085ce0bba878e294d1c8c20d1112cd.tar.gz |
s-s-d: Use a heap allocated formatted string for what to stop
Diffstat (limited to 'utils')
-rw-r--r-- | utils/start-stop-daemon.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index c2a81f4c1..479a1294b 100644 --- a/utils/start-stop-daemon.c +++ b/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"); |