Skip to content

Commit 9ff18fa

Browse files
peffgitster
authored andcommitted
fetch-pack: ignore SIGPIPE in sideband demuxer
If the other side feeds us a bogus pack, index-pack (or unpack-objects) may die early, before consuming all of its input. As a result, the sideband demuxer may get SIGPIPE (racily, depending on whether our data made it into the pipe buffer or not). If this happens and we are compiled with pthread support, it will take down the main thread, too. This isn't the end of the world, as the main process will just die() anyway when it sees index-pack failed. But it does mean we don't get a chance to say "fatal: index-pack failed" or similar. And it also means that we racily fail t5504, as we sometimes die() and sometimes are killed by SIGPIPE. So let's ignore SIGPIPE while demuxing the sideband. We are already careful to check the return value of write(), so we won't waste time writing to a broken pipe. The caller will notice the error return from the async thread, though in practice we don't even get that far, as we die() as soon as we see that index-pack failed. The non-sideband case is already fine; we let index-pack read straight from the socket, so there is no SIGPIPE at all. Technically the non-threaded async case is also OK without this (the forked async process gets SIGPIPE), but it's not worth distinguishing from the threaded case here. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9658846 commit 9ff18fa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

fetch-pack.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "version.h"
1616
#include "prio-queue.h"
1717
#include "sha1-array.h"
18+
#include "sigchain.h"
1819

1920
static int transfer_unpack_limit = -1;
2021
static int fetch_unpack_limit = -1;
@@ -671,9 +672,12 @@ static int everything_local(struct fetch_pack_args *args,
671672
static int sideband_demux(int in, int out, void *data)
672673
{
673674
int *xd = data;
675+
int ret;
674676

675-
int ret = recv_sideband("fetch-pack", xd[0], out);
677+
sigchain_push(SIGPIPE, SIG_IGN);
678+
ret = recv_sideband("fetch-pack", xd[0], out);
676679
close(out);
680+
sigchain_pop(SIGPIPE);
677681
return ret;
678682
}
679683

0 commit comments

Comments
 (0)