git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] credential: ignore SIGPIPE when writing to credential helpers

From
EBErik E Brady <brady@cisco.com>
Date
Mar 29, 2018, 18:00 UTC
Message-ID
<20180329180056.9941-1-brady@cisco.com>
In-Reply-To
<20180329175501.GE31833@sigill.intra.peff.net>

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>
---
 credential.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/credential.c b/credential.c
index 9747f47b1..62be651b0 100644
--- a/credential.c
+++ b/credential.c
@@ -5,6 +5,7 @@
 #include "run-command.h"
 #include "url.h"
 #include "prompt.h"
+#include "sigchain.h"
 
 void credential_init(struct credential *c)
 {
@@ -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;
-- 
2.16.3.dirty
Previous: Jeff KingNext: Jeff King
Message 5 of 9 in “credential: cred helper fast exit can cause SIGPIPE, crash”
  1. credential: cred helper fast exit can cause SIGPIPE, crashErik E Brady, Mar 28, 2018
  2. Jeff KingMar 29, 2018
  3. Erik Brady -X (brady - ROBERT HALF INTERNATIONAL INC at Cisco)Mar 29, 2018
  4. Jeff KingMar 29, 2018
  5. credential: ignore SIGPIPE when writing to credential helpersErik E Brady, Mar 29, 2018
  6. Jeff KingMar 29, 2018
  7. Erik Brady -X (brady - ROBERT HALF INTERNATIONAL INC at Cisco)Mar 29, 2018
  8. Jeff KingMar 29, 2018
  9. Junio C HamanoMar 29, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.