From b7f34187d08f2890e049abefff313ab6193d7619 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Fri, 8 Jun 2018 00:13:13 +0100 Subject: [PATCH] Don't keep char * from array_string temporary. The string might not be resolved as a compile-time constant, and the temporary object may be destroyed before the string within it is used. --- src/dinit.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dinit.cc b/src/dinit.cc index c865211..77ba20f 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -484,9 +484,10 @@ int dinit_main(int argc, char **argv) } // Fork and execute dinit-reboot. - const char *shutdown_exec = literal(SBINDIR) + "/shutdown"; - execl(shutdown_exec, shutdown_exec, "--system", cmd_arg, nullptr); - log(loglevel_t::ERROR, literal("Could not execute ") + SBINDIR + "/shutdown: ", strerror(errno)); + constexpr auto shutdown_exec = literal(SBINDIR) + "/shutdown"; + execl(shutdown_exec.c_str(), shutdown_exec.c_str(), "--system", cmd_arg, nullptr); + log(loglevel_t::ERROR, (literal("Could not execute ") + SBINDIR + "/shutdown: ").c_str(), + strerror(errno)); // PID 1 must not actually exit, although we should never reach this point: while (true) { @@ -748,8 +749,8 @@ static void sigquit_cb(eventloop_t &eloop) noexcept { // This performs an immediate shutdown, without service rollback. close_control_socket(); - const char *shutdown_exec = literal(SBINDIR) + "/shutdown"; - execl(shutdown_exec, shutdown_exec, "--system", (char *) 0); + constexpr auto shutdown_exec = literal(SBINDIR) + "/shutdown"; + execl(shutdown_exec.c_str(), shutdown_exec.c_str(), "--system", (char *) 0); log(loglevel_t::ERROR, literal("Error executing ") + SBINDIR + "/sbin/shutdown: ", strerror(errno)); sync(); // since a hard poweroff might be required at this point... } -- 2.25.1