From f9d41243d8499c5d7027177d5aa716d5b5859cd6 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 19 Jun 2018 17:46:12 -0500 Subject: start-stop-daemon: convert snprintf calls to xasprintf --- src/rc/start-stop-daemon.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c index a04a00ec..33f886c4 100644 --- a/src/rc/start-stop-daemon.c +++ b/src/rc/start-stop-daemon.c @@ -167,20 +167,20 @@ handle_signal(int sig) { int status; int serrno = errno; - char signame[10] = { '\0' }; + char *signame = NULL; switch (sig) { case SIGINT: - if (!signame[0]) - snprintf(signame, sizeof(signame), "SIGINT"); + if (!signame) + xasprintf(&signame, "SIGINT"); /* FALLTHROUGH */ case SIGTERM: - if (!signame[0]) - snprintf(signame, sizeof(signame), "SIGTERM"); + if (!signame) + xasprintf(&signame, "SIGTERM"); /* FALLTHROUGH */ case SIGQUIT: - if (!signame[0]) - snprintf(signame, sizeof(signame), "SIGQUIT"); + if (!signame) + xasprintf(&signame, "SIGQUIT"); eerrorx("%s: caught %s, aborting", applet, signame); /* NOTREACHED */ @@ -199,6 +199,9 @@ handle_signal(int sig) eerror("%s: caught unknown signal %d", applet, sig); } + /* free signame */ + free(signame); + /* Restore errno */ errno = serrno; } @@ -207,7 +210,6 @@ static char * expand_home(const char *home, const char *path) { char *opath, *ppath, *p, *nh; - size_t len; struct passwd *pw; if (!path || *path != '~') @@ -238,9 +240,7 @@ expand_home(const char *home, const char *path) return xstrdup(home); } - len = strlen(ppath) + strlen(home) + 1; - nh = xmalloc(len); - snprintf(nh, len, "%s%s", home, ppath); + xasprintf(&nh, "%s%s", home, ppath); free(opath); return nh; } -- cgit v1.2.3