Skip to content

Commit 8c925ef

Browse files
committed
smart protocol: validate progress message length
Ensure that the server has not sent us overly-large sideband messages (ensure that they are no more than `INT_MAX` bytes), then cast to `int`.
1 parent 7afe788 commit 8c925ef

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/transports/smart_protocol.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,14 @@ int git_smart__download_pack(
604604
} else if (pkt->type == GIT_PKT_PROGRESS) {
605605
if (t->progress_cb) {
606606
git_pkt_progress *p = (git_pkt_progress *) pkt;
607-
error = t->progress_cb(p->data, p->len, t->message_cb_payload);
607+
608+
if (p->len > INT_MAX) {
609+
git_error_set(GIT_ERROR_NET, "oversized progress message");
610+
error = GIT_ERROR;
611+
goto done;
612+
}
613+
614+
error = t->progress_cb(p->data, (int)p->len, t->message_cb_payload);
608615
}
609616
} else if (pkt->type == GIT_PKT_DATA) {
610617
git_pkt_data *p = (git_pkt_data *) pkt;
@@ -839,7 +846,14 @@ static int parse_report(transport_smart *transport, git_push *push)
839846
case GIT_PKT_PROGRESS:
840847
if (transport->progress_cb) {
841848
git_pkt_progress *p = (git_pkt_progress *) pkt;
842-
error = transport->progress_cb(p->data, p->len, transport->message_cb_payload);
849+
850+
if (p->len > INT_MAX) {
851+
git_error_set(GIT_ERROR_NET, "oversized progress message");
852+
error = GIT_ERROR;
853+
goto done;
854+
}
855+
856+
error = transport->progress_cb(p->data, (int)p->len, transport->message_cb_payload);
843857
}
844858
break;
845859
default:

0 commit comments

Comments
 (0)