Skip to content

Commit 6850b51

Browse files
author
Edward Thomson
committed
Merge branch '25_smartpktparse' into maint/v0.25
2 parents ab8a0fd + 2fdef64 commit 6850b51

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/transports/smart_pkt.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,23 @@ int git_pkt_parse_line(
427427
if (bufflen > 0 && bufflen < (size_t)len)
428428
return GIT_EBUFS;
429429

430+
/*
431+
* The length has to be exactly 0 in case of a flush
432+
* packet or greater than PKT_LEN_SIZE, as the decoded
433+
* length includes its own encoded length of four bytes.
434+
*/
435+
if (len != 0 && len < PKT_LEN_SIZE)
436+
return GIT_ERROR;
437+
430438
line += PKT_LEN_SIZE;
431439
/*
432-
* TODO: How do we deal with empty lines? Try again? with the next
433-
* line?
440+
* The Git protocol does not specify empty lines as part
441+
* of the protocol. Not knowing what to do with an empty
442+
* line, we should return an error upon hitting one.
434443
*/
435444
if (len == PKT_LEN_SIZE) {
436-
*head = NULL;
437-
*out = line;
438-
return 0;
445+
giterr_set_str(GITERR_NET, "Invalid empty packet");
446+
return GIT_ERROR;
439447
}
440448

441449
if (len == 0) { /* Flush pkt */

src/transports/smart_protocol.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,6 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
763763
line_len -= (line_end - line);
764764
line = line_end;
765765

766-
/* When a valid packet with no content has been
767-
* read, git_pkt_parse_line does not report an
768-
* error, but the pkt pointer has not been set.
769-
* Handle this by skipping over empty packets.
770-
*/
771-
if (pkt == NULL)
772-
continue;
773-
774766
error = add_push_report_pkt(push, pkt);
775767

776768
git_pkt_free(pkt);
@@ -825,9 +817,6 @@ static int parse_report(transport_smart *transport, git_push *push)
825817

826818
error = 0;
827819

828-
if (pkt == NULL)
829-
continue;
830-
831820
switch (pkt->type) {
832821
case GIT_PKT_DATA:
833822
/* This is a sideband packet which contains other packets */

0 commit comments

Comments
 (0)