• Jeff King's avatar
    pkt-line: prepare buffer before handling ERR packets · 533ddba4
    Jeff King authored
    Since 2d103c31 (pack-protocol.txt: accept error packets in any
    context, 2018-12-29), the pktline code will detect an ERR packet and die
    automatically, saving the caller from dealing with it. But we do so too
    early in the function, before we have terminated the buffer with a NUL.
    As a result, passing the ERR message to die() may result in us printing
    random cruft from a previous packet. This doesn't trigger memory tools
    like ASan because we reuse the same buffer over and over (so the
    contents are valid and initialized; they're just stale).
    We can see demonstrate this by tightening the regex we use to match the
    error message in t5516; without this patch, git-fetch will accidentally
    print the capabilities from the (much longer) initial packet we
    By moving the ERR code later in the function we get a few other
    benefits, too:
      - we'll now chomp any newline sent by the other side (which is what we
        want, since die() will add its own newline)
      - we'll now mention the ERR packet with GIT_TRACE_PACKET
    Signed-off-by: 's avatarJeff King <peff@peff.net>
    Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
pkt-line.c 13 KB