Fix possible NULL deref in run() error handling

When we added support for using popen() to run(), to log the output, we
forgot to update the error handling path.  Found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-04-14 09:45:41 +02:00
1 parent 7d831170ae
commit ff937576ea
1 file changed
+4 -2
+4 -2
View File
@@ -97,12 +97,14 @@ static int do_redirect(void)
*/ */
int run(char *cmd, char *log) int run(char *cmd, char *log)
{ {
char *args[NUM_ARGS + 1] = { 0 };
int status, result, i = 0; int status, result, i = 0;
char *args[NUM_ARGS + 1], *arg;
char *backup = NULL; char *backup = NULL;
pid_t pid; pid_t pid;
if (!log) { if (!log) {
char *arg;
/* We must create a copy that is possible to modify. */ /* We must create a copy that is possible to modify. */
backup = arg = strdup(cmd); backup = arg = strdup(cmd);
if (!arg) if (!arg)
@@ -164,7 +166,7 @@ int run(char *cmd, char *log)
_exit(rc); _exit(rc);
} else if (-1 == pid) { } else if (-1 == pid) {
_pe("%s", args[0]); _pe("%s", !log ? args[0] : cmd);
if (backup) if (backup)
free(backup); free(backup);