diff options
author | Phil Pennock <pdp@exim.org> | 2011-08-28 16:27:01 -0400 |
---|---|---|
committer | Phil Pennock <pdp@exim.org> | 2011-08-28 16:27:01 -0400 |
commit | ac53fcdaf9c772ee8e70ca4f14ed19b39e12eb68 (patch) | |
tree | 392bda16315e6e80f1aedd03dd0a31efe8ccd23d /src | |
parent | 555ae6af39312f43b1d38d8da05cf4368b933015 (diff) |
Handle ${run} returning more data than OS pipe buffer size.
Patch from Holger Weiß.
fixes bug 1131
Diffstat (limited to 'src')
-rw-r--r-- | src/src/expand.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/src/expand.c b/src/src/expand.c index fb6d6922b..ec4dd71f9 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -4404,13 +4404,24 @@ while (*s != 0) (void)close(fd_in); + /* Read the pipe to get the command's output into $value (which is kept + in lookup_value). Read during execution, so that if the output exceeds + the OS pipe buffer limit, we don't block forever. */ + + f = fdopen(fd_out, "rb"); + sigalrm_seen = FALSE; + alarm(60); + lookup_value = cat_file(f, lookup_value, &lsize, &lptr, NULL); + alarm(0); + (void)fclose(f); + /* Wait for the process to finish, applying the timeout, and inspect its return code for serious disasters. Simple non-zero returns are passed on. */ - if ((runrc = child_close(pid, 60)) < 0) + if (sigalrm_seen == TRUE || (runrc = child_close(pid, 30)) < 0) { - if (runrc == -256) + if (sigalrm_seen == TRUE || runrc == -256) { expand_string_message = string_sprintf("command timed out"); killpg(pid, SIGKILL); /* Kill the whole process group */ @@ -4426,14 +4437,6 @@ while (*s != 0) goto EXPAND_FAILED; } - - /* Read the pipe to get the command's output into $value (which is kept - in lookup_value). */ - - f = fdopen(fd_out, "rb"); - lookup_value = NULL; - lookup_value = cat_file(f, lookup_value, &lsize, &lptr, NULL); - (void)fclose(f); } /* Process the yes/no strings; $value may be useful in both cases */ |