Skip to content

Commit 2fdef64

Browse files
pks-tEdward Thomson
authored andcommitted
smart_pkt: treat empty packet lines as error
The Git protocol does not specify what should happen in the case of an empty packet line (that is a packet line "0004"). We currently indicate success, but do not return a packet in the case where we hit an empty line. The smart protocol was not prepared to handle such packets in all cases, though, resulting in a `NULL` pointer dereference. Fix the issue by returning an error instead. As such kind of packets is not even specified by upstream, this is the right thing to do.
1 parent 66e3774 commit 2fdef64

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/transports/smart_pkt.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,13 @@ int git_pkt_parse_line(
437437

438438
line += PKT_LEN_SIZE;
439439
/*
440-
* TODO: How do we deal with empty lines? Try again? with the next
441-
* 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.
442443
*/
443444
if (len == PKT_LEN_SIZE) {
444-
*head = NULL;
445-
*out = line;
446-
return 0;
445+
giterr_set_str(GITERR_NET, "Invalid empty packet");
446+
return GIT_ERROR;
447447
}
448448

449449
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)