Skip to content

Commit 786426e

Browse files
committed
smart_pkt: check whether error packets are prefixed with "ERR "
In the `git_pkt_parse_line` function, we determine what kind of packet a given packet line contains by simply checking for the prefix of that line. Except for "ERR" packets, we always only check for the immediate identifier without the trailing space (e.g. we check for an "ACK" prefix, not for "ACK "). But for "ERR" packets, we do in fact include the trailing space in our check. This is not really much of a problem at all, but it is inconsistent with all the other packet types and thus causes confusion when the `err_pkt` function just immediately skips the space without checking whether it overflows the line buffer. Adjust the check in `git_pkt_parse_line` to not include the trailing space and instead move it into `err_pkt` for consistency.
1 parent 40fd84c commit 786426e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/transports/smart_pkt.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ static int comment_pkt(git_pkt **out, const char *line, size_t len)
107107

108108
static int err_pkt(git_pkt **out, const char *line, size_t len)
109109
{
110-
git_pkt_err *pkt;
110+
git_pkt_err *pkt = NULL;
111111
size_t alloclen;
112112

113113
/* Remove "ERR " from the line */
114+
if (git__prefixncmp(line, len, "ERR "))
115+
goto out_err;
114116
line += 4;
115117
len -= 4;
116118

@@ -127,6 +129,11 @@ static int err_pkt(git_pkt **out, const char *line, size_t len)
127129
*out = (git_pkt *) pkt;
128130

129131
return 0;
132+
133+
out_err:
134+
giterr_set(GITERR_NET, "error parsing ERR pkt-line");
135+
git__free(pkt);
136+
return -1;
130137
}
131138

132139
static int data_pkt(git_pkt **out, const char *line, size_t len)
@@ -463,7 +470,7 @@ int git_pkt_parse_line(
463470
ret = ack_pkt(head, line, len);
464471
else if (!git__prefixncmp(line, len, "NAK"))
465472
ret = nak_pkt(head);
466-
else if (!git__prefixncmp(line, len, "ERR "))
473+
else if (!git__prefixncmp(line, len, "ERR"))
467474
ret = err_pkt(head, line, len);
468475
else if (*line == '#')
469476
ret = comment_pkt(head, line, len);

0 commit comments

Comments
 (0)