Commit a7d9d93d by Chris Hescock

Buffer sideband packet data

The inner packet may be split across multiple sideband packets.
parent 700f0aff
...@@ -719,22 +719,20 @@ static int add_push_report_pkt(git_push *push, git_pkt *pkt) ...@@ -719,22 +719,20 @@ static int add_push_report_pkt(git_push *push, git_pkt *pkt)
return 0; return 0;
} }
static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt) static int add_push_report_sideband_pkt(git_push *push, git_buf *data_pkt_buf)
{ {
git_pkt *pkt; git_pkt *pkt;
const char *line = data_pkt->data, *line_end; const char *line_end;
size_t line_len = data_pkt->len;
int error; int error;
while (line_len > 0) { while (data_pkt_buf->size > 0) {
error = git_pkt_parse_line(&pkt, line, &line_end, line_len); error = git_pkt_parse_line(&pkt, data_pkt_buf->ptr, &line_end, data_pkt_buf->size);
if (error < 0) if (error < 0)
return error; return error;
/* Advance in the buffer */ /* Advance in the buffer */
line_len -= (line_end - line); git_buf_consume(data_pkt_buf, line_end);
line = line_end;
error = add_push_report_pkt(push, pkt); error = add_push_report_pkt(push, pkt);
...@@ -753,6 +751,8 @@ static int parse_report(transport_smart *transport, git_push *push) ...@@ -753,6 +751,8 @@ static int parse_report(transport_smart *transport, git_push *push)
const char *line_end = NULL; const char *line_end = NULL;
gitno_buffer *buf = &transport->buffer; gitno_buffer *buf = &transport->buffer;
int error, recvd; int error, recvd;
git_buf data_pkt_buf = GIT_BUF_INIT;
git_pkt_data *data_pkt;
for (;;) { for (;;) {
if (buf->offset > 0) if (buf->offset > 0)
...@@ -761,16 +761,21 @@ static int parse_report(transport_smart *transport, git_push *push) ...@@ -761,16 +761,21 @@ static int parse_report(transport_smart *transport, git_push *push)
else else
error = GIT_EBUFS; error = GIT_EBUFS;
if (error < 0 && error != GIT_EBUFS) if (error < 0 && error != GIT_EBUFS) {
return -1; error = -1;
goto done;
}
if (error == GIT_EBUFS) { if (error == GIT_EBUFS) {
if ((recvd = gitno_recv(buf)) < 0) if ((recvd = gitno_recv(buf)) < 0) {
return recvd; error = recvd;
goto done;
}
if (recvd == 0) { if (recvd == 0) {
giterr_set(GITERR_NET, "early EOF"); giterr_set(GITERR_NET, "early EOF");
return GIT_EEOF; error = GIT_EEOF;
goto done;
} }
continue; continue;
} }
...@@ -781,8 +786,14 @@ static int parse_report(transport_smart *transport, git_push *push) ...@@ -781,8 +786,14 @@ static int parse_report(transport_smart *transport, git_push *push)
switch (pkt->type) { switch (pkt->type) {
case GIT_PKT_DATA: case GIT_PKT_DATA:
/* This is a sideband packet which contains other packets */ /* This is a sideband packet which contains other packets
error = add_push_report_sideband_pkt(push, (git_pkt_data *)pkt); * Buffer the data in case the inner packet is split
* across multiple sideband packets */
data_pkt = (git_pkt_data *)pkt;
git_buf_put(&data_pkt_buf, data_pkt->data, data_pkt->len);
error = add_push_report_sideband_pkt(push, &data_pkt_buf);
if (error == GIT_EBUFS)
error = 0;
break; break;
case GIT_PKT_ERR: case GIT_PKT_ERR:
giterr_set(GITERR_NET, "report-status: Error reported: %s", giterr_set(GITERR_NET, "report-status: Error reported: %s",
...@@ -803,12 +814,24 @@ static int parse_report(transport_smart *transport, git_push *push) ...@@ -803,12 +814,24 @@ static int parse_report(transport_smart *transport, git_push *push)
git_pkt_free(pkt); git_pkt_free(pkt);
/* add_push_report_pkt returns GIT_ITEROVER when it receives a flush */ /* add_push_report_pkt returns GIT_ITEROVER when it receives a flush */
if (error == GIT_ITEROVER) if (error == GIT_ITEROVER) {
return 0; error = 0;
if (data_pkt_buf.size > 0) {
/* If there was data remaining in the pack data buffer,
* then the server sent a partial pkt-line */
giterr_set(GITERR_NET, "Incomplete pack data pkt-line");
error = GIT_ERROR;
}
goto done;
}
if (error < 0) if (error < 0) {
return error; goto done;
} }
}
done:
git_buf_free(&data_pkt_buf);
return error;
} }
static int add_ref_from_push_spec(git_vector *refs, push_spec *push_spec) static int add_ref_from_push_spec(git_vector *refs, push_spec *push_spec)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment