diff options
authorJon Simons <>2018-02-08 18:47:50 (GMT)
committerJunio C Hamano <>2018-02-08 20:37:40 (GMT)
commitbb1356dc643e1488ccc1924ab674f6cbbe615f74 (patch)
parentbc9d4dc5b07c05c7b26a4e781b7538db7c775fc3 (diff)
always check for NULL return from packet_read_line()
The packet_read_line() function will die if it sees any protocol or socket errors. But it will return NULL for a flush packet; some callers which are not expecting this may dereference NULL if they get an unexpected flush. This would involve the other side breaking protocol, but we should flag the error rather than segfault. Signed-off-by: Jon Simons <> Reviewed-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2 files changed, 4 insertions, 0 deletions
diff --git a/remote-curl.c b/remote-curl.c
index 0053b09..9903077 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -339,6 +339,8 @@ static struct discovery *discover_refs(const char *service, int for_push)
* pkt-line matches our request.
line = packet_read_line_buf(&last->buf, &last->len, NULL);
+ if (!line)
+ die("invalid server response; expected service, got flush packet");
strbuf_addf(&exp, "# service=%s", service);
diff --git a/send-pack.c b/send-pack.c
index 2112d3b..8d9190f 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -137,6 +137,8 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
static int receive_unpack_status(int in)
const char *line = packet_read_line(in, NULL);
+ if (!line)
+ return error(_("unexpected flush packet while reading remote unpack status"));
if (!skip_prefix(line, "unpack ", &line))
return error(_("unable to parse remote unpack status: %s"), line);
if (strcmp(line, "ok"))