Skip to content

Commit

Permalink
http-push: trim trailing newline from remote symref
Browse files Browse the repository at this point in the history
When we fetch a symbolic ref file from the remote, we get
the whole string "ref: refs/heads/master\n", recognize it by
skipping past the "ref: ", and store the rest. We should
chomp the trailing newline.

This bug was introduced in ae021d8 (use skip_prefix to avoid
magic numbers, 2014-06-18), which did not notice that the
length computation fed to xmemdupz was quietly tweaked by 1
to account for this.

We can solve it by explicitly trimming the newline, which is
more obvious. Note that we use strbuf_rtrim here, which will
actually cut off any trailing whitespace, not just a single
newline. This is a good thing, though, as it makes our
parsing more liberal (and spaces are not valid in refnames
anyway).

Signed-off-by: Jeff King <peff@peff.net>
Tested-by: Kyle J. McKay <mackyle@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jan 14, 2015
1 parent 3c84ac8 commit f6786c8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions http-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,9 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
if (buffer.len == 0)
return;

/* Cut off trailing newline. */
strbuf_rtrim(&buffer);

/* If it's a symref, set the refname; otherwise try for a sha1 */
if (skip_prefix(buffer.buf, "ref: ", &name)) {
*symref = xmemdupz(name, buffer.len - (name - buffer.buf));
Expand Down

0 comments on commit f6786c8

Please sign in to comment.