Skip to content

Commit

Permalink
credential: ignore SIGPIPE when writing to credential helpers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jeff King <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Erik E Brady authored and gitster committed Mar 29, 2018
1 parent d32eb83 commit a0d51e8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions credential.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "run-command.h"
#include "url.h"
#include "prompt.h"
#include "sigchain.h"

void credential_init(struct credential *c)
{
Expand Down Expand Up @@ -227,8 +228,10 @@ static int run_credential_helper(struct credential *c,
return -1;

fp = xfdopen(helper.in, "w");
sigchain_push(SIGPIPE, SIG_IGN);
credential_write(c, fp);
fclose(fp);
sigchain_pop(SIGPIPE);

if (want_output) {
int r;
Expand Down

0 comments on commit a0d51e8

Please sign in to comment.