From: Davin McCall Date: Thu, 7 Jun 2018 23:13:13 +0000 (+0100) Subject: Don't keep char * from array_string temporary. X-Git-Tag: v0.2.0~3 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b7f34187d08f2890e049abefff313ab6193d7619;p=oweals%2Fdinit.git 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. --- 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... }