1 Received: by 10.52.8.42 with SMTP id o10csp1233223vda;
2 Mon, 12 Jan 2015 18:34:05 -0800 (PST)
3 X-Received: by 10.66.169.209 with SMTP id ag17mr47797760pac.62.1421116444826;
4 Mon, 12 Jan 2015 18:34:04 -0800 (PST)
5 Return-Path: <git-owner@vger.kernel.org>
6 Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67])
7 by mx.google.com with ESMTP id bc4si25219235pdb.237.2015.01.12.18.33.20;
8 Mon, 12 Jan 2015 18:34:04 -0800 (PST)
9 Received-SPF: none (google.com: git-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67;
10 Authentication-Results: mx.google.com;
11 spf=none (google.com: git-owner@vger.kernel.org does not designate permitted sender hosts) smtp.mail=git-owner@vger.kernel.org
12 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
13 id S1753325AbbAMC27 (ORCPT <rfc822;gregory.0xf0@gmail.com>
14 + 99 others); Mon, 12 Jan 2015 21:28:59 -0500
15 Received: from cloud.peff.net ([50.56.180.127]:33639 "HELO cloud.peff.net"
16 rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
17 id S1752546AbbAMC26 (ORCPT <rfc822;git@vger.kernel.org>);
18 Mon, 12 Jan 2015 21:28:58 -0500
19 Received: (qmail 20563 invoked by uid 102); 13 Jan 2015 02:28:59 -0000
20 Received: from Unknown (HELO peff.net) (10.0.1.1)
21 by cloud.peff.net (qpsmtpd/0.84) with SMTP; Mon, 12 Jan 2015 20:28:58 -0600
22 Received: (qmail 22943 invoked by uid 107); 13 Jan 2015 02:29:19 -0000
23 Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7)
24 by peff.net (qpsmtpd/0.84) with SMTP; Mon, 12 Jan 2015 21:29:19 -0500
25 Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Mon, 12 Jan 2015 21:28:58 -0500
26 Date: Mon, 12 Jan 2015 21:28:58 -0500
27 From: Jeff King <peff@peff.net>
28 To: git@vger.kernel.org
29 Cc: Junio C Hamano <gitster@pobox.com>
30 Subject: [PATCH] http-push: trim trailing newline from remote symref
31 Message-ID: <20150113022857.GA4087@peff.net>
33 Content-Type: text/plain; charset=utf-8
34 Content-Disposition: inline
35 Sender: git-owner@vger.kernel.org
37 List-ID: <git.vger.kernel.org>
38 X-Mailing-List: git@vger.kernel.org
40 When we fetch a symbolic ref file from the remote, we get
41 the whole string "ref: refs/heads/master\n", recognize it by
42 skipping past the "ref: ", and store the rest. We should
43 chomp the trailing newline.
45 This bug was introduced in ae021d8 (use skip_prefix to avoid
46 magic numbers, 2014-06-18), which did not notice that the
47 length computation fed to xmemdupz was quietly tweaked by 1
50 We can solve it by explicitly trimming the newline, which is
51 more obvious. Note that we use strbuf_rtrim here, which will
52 actually cut off any trailing whitespace, not just a single
53 newline. This is a good thing, though, as it makes our
54 parsing more liberal (and spaces are not valid in refnames
57 Signed-off-by: Jeff King <peff@peff.net>
59 This is a regression in v2.1.0.
61 It was causing t5540 to fail, but I realized I have been building with
62 NO_EXPAT for a while, so I didn't notice. Frankly, I'm kind of surprised
63 and disturbed that nobody noticed it before now. More evidence that we
64 can kill off dumb http-push? I would have thought somebody else would
65 have noticed the test failure, though.
67 I am embarrassed to have introduced the bug during a refactoring patch.
68 But in my defense, the original code was quite subtle and horrible, and
69 I think the end result at least is much obvious (and is a good point in
70 favor of skip_prefix's existence!). The original came from eecc836
71 (Another memory overrun in http-push.c, 2007-03-01). Looking at that
72 patch, I can't understand how the code before it ever worked in the
76 1 file changed, 3 insertions(+)
78 diff --git a/http-push.c b/http-push.c
79 index 26dfa67..184d24a 100644
82 @@ -1577,6 +1577,9 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
86 + /* Cut off trailing newline. */
87 + strbuf_rtrim(&buffer);
89 /* If it's a symref, set the refname; otherwise try for a sha1 */
90 if (skip_prefix(buffer.buf, "ref: ", &name)) {
91 *symref = xmemdupz(name, buffer.len - (name - buffer.buf));