always check for NULL return from packet_read_line()
authorJon Simons <jon@jonsimons.org>
Thu, 8 Feb 2018 18:47:50 +0000 (13:47 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Feb 2018 20:37:40 +0000 (12:37 -0800)
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 <jon@jonsimons.org>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote-curl.c
send-pack.c
index 0053b09549ab419ab8f2da2c519d689f5e0d83b3..99030774713221d605a2731ca2f3fa46d9115631 100644 (file)
@@ -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_reset(&exp);
                strbuf_addf(&exp, "# service=%s", service);
index 2112d3b27ad21e1d457b08a3aa71a811b5e8ee79..8d9190f5e7815c6b2f18afd266643a8c862e526e 100644 (file)
@@ -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"))