From 1846d2f078a61650c3ed97bcb50507393ef87103 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 22 Jun 2018 19:52:22 +0200 Subject: [PATCH] Prevent killing unexpected process A missing initialization (fixed by the previous commit) leaded to kill unexpected process. In order to prevent consequences of similar errors in the future, never call kill() with a non-positive PID. See . --- app/src/sys/unix/command.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/sys/unix/command.c b/app/src/sys/unix/command.c index 89295e57..0083a93b 100644 --- a/app/src/sys/unix/command.c +++ b/app/src/sys/unix/command.c @@ -1,9 +1,11 @@ #include "command.h" #include +#include #include #include #include +#include "log.h" pid_t cmd_execute(const char *path, const char *const argv[]) { pid_t pid = fork(); @@ -20,6 +22,10 @@ pid_t cmd_execute(const char *path, const char *const argv[]) { } SDL_bool cmd_terminate(pid_t pid) { + if (pid <= 0) { + LOGC("Requested to kill %d, this is an error. Please report the bug.\n", (int) pid); + abort(); + } return kill(pid, SIGTERM) != -1; }