aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Zangerl <az@debian.org>2012-09-03 23:07:47 +0200
committerMatthias Andree <matthias.andree@gmx.de>2012-09-03 23:10:57 +0200
commitf77204551bb10e8c05acd8a607ee9db4ad48cf47 (patch)
tree068f775f0dd6477a5da37288ee92f3a0158c8546
parent2629c4511c68729d98acfd08637c1f00d3807f49 (diff)
downloadfetchmail-f77204551bb10e8c05acd8a607ee9db4ad48cf47.tar.gz
fetchmail-f77204551bb10e8c05acd8a607ee9db4ad48cf47.tar.bz2
fetchmail-f77204551bb10e8c05acd8a607ee9db4ad48cf47.zip
Fix: combination of --plugin and -f - fails
scenario: you want to remote-control fetchmail, but you don't want to write passwords into files, so you feed fetchmail a minimal rcfile via stdin with -f -. this by itself works fine. if you also want or need to use a --plugin (eg. socat for socks), then things fail badly: the plugin is run without a stdin fd, hence can't take input from fetchmail, lots of fun ensues. plugins without -f - work fine, it's just the combination that fails. explanation: the root cause is rcfile_y.y, line 493, which closes whatever fd carried the rcfile. with -f - this closes fetchmail's stdin - and so far that's unproblematic. however, in socket.c lines 166ff things go wrong: fetchmail sets up the plugin with a socketpair, which will likely include the first unused fd - and fd zero is now indeed unused. in line 180ff a dup2 replumbing from "that fd" (=zero) to zero is performed - and then "that fd" is closed. and hey presto, we've got no fd zero = stdin for the plugin. solution: the simplest solution (patch attached) is to make the fclose of the rcfile conditional, ie. don't close if it's stdin. in the long run the dup2+close code might be made more robust by not doing a dup2+close if fd[0] is already 0 or 1.
-rw-r--r--rcfile_y.y3
1 files changed, 2 insertions, 1 deletions
diff --git a/rcfile_y.y b/rcfile_y.y
index b32a6b0c..91de6146 100644
--- a/rcfile_y.y
+++ b/rcfile_y.y
@@ -490,7 +490,8 @@ int prc_parse_file (const char *pathname, const flag securecheck)
yyparse(); /* parse entire file */
- fclose(yyin); /* not checking this should be safe, file mode was r */
+ if (yyin != stdin)
+ fclose(yyin); /* not checking this should be safe, file mode was r */
if (prc_errflag)
return(PS_SYNTAX);