Skip to content

Commit 62494bf

Browse files
committed
transports: smart: abort receiving packets on end of stream
When trying to receive packets from the remote, we loop until either an error distinct to `GIT_EBUFS` occurs or until we successfully parsed the packet. This does not honor the case where we are looping over an already closed socket which has no more data, leaving us in an infinite loop if we got a bogus packet size or if the remote hang up. Fix the issue by returning `GIT_EEOF` when we cannot read data from the socket anymore.
1 parent 61530c4 commit 62494bf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/transports/smart_protocol.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,12 @@ static int recv_pkt(git_pkt **out, gitno_buffer *buf)
222222
if (error < 0 && error != GIT_EBUFS)
223223
return error;
224224

225-
if ((ret = gitno_recv(buf)) < 0)
225+
if ((ret = gitno_recv(buf)) < 0) {
226226
return ret;
227+
} else if (ret == 0) {
228+
giterr_set(GITERR_NET, "early EOF");
229+
return GIT_EEOF;
230+
}
227231
} while (error);
228232

229233
gitno_consume(buf, line_end);

0 commit comments

Comments
 (0)