Submitter | Yuya Nishihara |
---|---|
Date | Aug. 6, 2016, 4:51 a.m. |
Message ID | <e59b4315a3f8602582f0.1470459099@mimosa> |
Download | mbox | patch |
Permalink | /patch/16152/ |
State | Accepted |
Headers | show |
Comments
Yes, please. Excerpts from Yuya Nishihara's message of 2016-08-06 13:51:39 +0900: > # HG changeset patch > # User Yuya Nishihara <yuya@tcha.org> > # Date 1470399693 -32400 > # Fri Aug 05 21:21:33 2016 +0900 > # Node ID e59b4315a3f8602582f0d39e1c531faaa3119982 > # Parent 56e9357be6b2704678331999e8b4b02777fc724b > chg: just take it as EOF if recv() returns 0 > > hgc->sockfd is a blocking stream socket. recv() should never return 0 other > than EOF. > > See 4fc4b8cc9957 for the original problem. > > diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c > --- a/contrib/chg/hgclient.c > +++ b/contrib/chg/hgclient.c > @@ -126,15 +126,10 @@ static void readchannel(hgclient_t *hgc) > return; /* assumes input request */ > > size_t cursize = 0; > - int emptycount = 0; > while (cursize < hgc->ctx.datasize) { > rsize = recv(hgc->sockfd, hgc->ctx.data + cursize, > hgc->ctx.datasize - cursize, 0); > - /* rsize == 0 normally indicates EOF, while it's also a valid > - * packet size for unix socket. treat it as EOF and abort if > - * we get many empty responses in a row. */ > - emptycount = (rsize == 0 ? emptycount + 1 : 0); > - if (rsize < 0 || emptycount > 20) > + if (rsize < 1) > abortmsg("failed to read data block"); > cursize += rsize; > }
On 08/06/2016 11:42 AM, Jun Wu wrote: > Yes, please. Pushed, thanks > > Excerpts from Yuya Nishihara's message of 2016-08-06 13:51:39 +0900: >> # HG changeset patch >> # User Yuya Nishihara <yuya@tcha.org> >> # Date 1470399693 -32400 >> # Fri Aug 05 21:21:33 2016 +0900 >> # Node ID e59b4315a3f8602582f0d39e1c531faaa3119982 >> # Parent 56e9357be6b2704678331999e8b4b02777fc724b >> chg: just take it as EOF if recv() returns 0 >> >> hgc->sockfd is a blocking stream socket. recv() should never return 0 other >> than EOF. >> >> See 4fc4b8cc9957 for the original problem. >> >> diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c >> --- a/contrib/chg/hgclient.c >> +++ b/contrib/chg/hgclient.c >> @@ -126,15 +126,10 @@ static void readchannel(hgclient_t *hgc) >> return; /* assumes input request */ >> >> size_t cursize = 0; >> - int emptycount = 0; >> while (cursize < hgc->ctx.datasize) { >> rsize = recv(hgc->sockfd, hgc->ctx.data + cursize, >> hgc->ctx.datasize - cursize, 0); >> - /* rsize == 0 normally indicates EOF, while it's also a valid >> - * packet size for unix socket. treat it as EOF and abort if >> - * we get many empty responses in a row. */ >> - emptycount = (rsize == 0 ? emptycount + 1 : 0); >> - if (rsize < 0 || emptycount > 20) >> + if (rsize < 1) >> abortmsg("failed to read data block"); >> cursize += rsize; >> } > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel >
Patch
diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c --- a/contrib/chg/hgclient.c +++ b/contrib/chg/hgclient.c @@ -126,15 +126,10 @@ static void readchannel(hgclient_t *hgc) return; /* assumes input request */ size_t cursize = 0; - int emptycount = 0; while (cursize < hgc->ctx.datasize) { rsize = recv(hgc->sockfd, hgc->ctx.data + cursize, hgc->ctx.datasize - cursize, 0); - /* rsize == 0 normally indicates EOF, while it's also a valid - * packet size for unix socket. treat it as EOF and abort if - * we get many empty responses in a row. */ - emptycount = (rsize == 0 ? emptycount + 1 : 0); - if (rsize < 0 || emptycount > 20) + if (rsize < 1) abortmsg("failed to read data block"); cursize += rsize; }