Skip to content

Commit f6786c8

Browse files
peffgitster
authored andcommitted
http-push: trim trailing newline from remote symref
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 <[email protected]> Tested-by: Kyle J. McKay <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c84ac8 commit f6786c8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

http-push.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,9 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
15771577
if (buffer.len == 0)
15781578
return;
15791579

1580+
/* Cut off trailing newline. */
1581+
strbuf_rtrim(&buffer);
1582+
15801583
/* If it's a symref, set the refname; otherwise try for a sha1 */
15811584
if (skip_prefix(buffer.buf, "ref: ", &name)) {
15821585
*symref = xmemdupz(name, buffer.len - (name - buffer.buf));

0 commit comments

Comments
 (0)