credential: ignore SIGPIPE when writing to credential helpers

The credential subsystem can trigger SIGPIPE when writing to an external helper if that helper closes its stdin before reading the whole input. Normally this is rare, since helpers would need to read that input to make a decision about how to respond, but: 1. It's reasonable to configure a helper which only handles "get" while ignoring "store". Such a handler might not read stdin for "store", thereby rapidly closing stdin upon helper exit. 2. A broken or misbehaving helper might exit immediately. That's an error, but it's not reasonable for it to take down the parent Git process with SIGPIPE. Even with such a helper, seeing this problem should be rare. Getting SIGPIPE requires the helper racily exiting before we've written the fairly small credential output. Signed-off-by: Erik E Brady <brady@cisco.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Erik E Brady committed Mar 29, 2018 at 11:00 UTC a0d51e8d0e866538632b16e13a5f51bc80eacf48
1 file changed +3
credential.c
+3
@@ -5,6 +5,7 @@
5 #include "run-command.h"
6 #include "url.h"
7 #include "prompt.h"
8 +#include "sigchain.h"
9
10 void credential_init(struct credential *c)
11 {
@@ -227,8 +228,10 @@ static int run_credential_helper(struct credential *c,
228 return -1;
229
230 fp = xfdopen(helper.in, "w");
231 + sigchain_push(SIGPIPE, SIG_IGN);
232 credential_write(c, fp);
233 fclose(fp);
234 + sigchain_pop(SIGPIPE);
235
236 if (want_output) {
237 int r;