Skip to content

Commit

Permalink
correctly check input parameter in exec_sync; close pipe with pclose …
Browse files Browse the repository at this point in the history
…to avoid leaving unfreed structs in kernel; correctly handle errors in exec_syc
  • Loading branch information
ionutrazvanionita committed Sep 18, 2015
1 parent f2ab4c4 commit eef9fa7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions modules/exec/exec.c
Expand Up @@ -431,8 +431,8 @@ int exec_sync(struct sip_msg* msg, str* command, str* input, gparam_p outvar, gp
int ret;
FILE *pin, *pout, *perr;

if (input || outvar || errvar) {
pid = __popen3(command->s, input ? &pin : NULL,
if ((input && input->len && input->s) || outvar || errvar) {
pid = __popen3(command->s, (input&&input->len&&input->s) ? &pin : NULL,
outvar ? &pout : NULL,
errvar ? &perr : NULL);
} else {
Expand All @@ -457,6 +457,7 @@ int exec_sync(struct sip_msg* msg, str* command, str* input, gparam_p outvar, gp
ser_error=E_EXEC;
goto error;
}

pclose(pin);
}

Expand All @@ -465,14 +466,16 @@ int exec_sync(struct sip_msg* msg, str* command, str* input, gparam_p outvar, gp
if (outvar) {
if (read_and_write2var(msg, &pout, outvar) < 0) {
LM_ERR("failed reading stdout from pipe\n");
return -1;
ret = -1;
goto error;
}
}

if (errvar) {
if (read_and_write2var(msg, &perr, errvar) < 0) {
LM_ERR("failed reading stderr from pipe\n");
return -1;
ret = -1;
goto error;
}
}

Expand Down Expand Up @@ -561,7 +564,7 @@ int start_async_exec(struct sip_msg* msg, str* command, str* input,
goto error2;
}

fclose(pout);
pclose(pout);

/* async started with success */
return 1;
Expand Down

0 comments on commit eef9fa7

Please sign in to comment.