Skip to content

Commit 95405ba

Browse files
raalkmlgitster
authored andcommitted
Quote LF in urls git fetch saves in FETCH_HEAD
The fmt-merge-msg does a strong syntax checking of its input and fails with if it is incorrect. The LF character is the only character important for fmt-merge-msg. As the url in FETCH_HEAD plays only informational role, a quoted representation of the url should be good and true enough. The url often comes from either user-editable config or command line, so it is reasonable to expect all kinds of characters in it, including the characters which the format of FETCH_HEAD considers special (line separator in this case). Noticed and reported by Hugo Mildenberger. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1a28725 commit 95405ba

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

builtin-fetch.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,18 @@ static int store_updated_refs(const char *url, const char *remote_name,
353353
kind);
354354
note_len += sprintf(note + note_len, "'%s' of ", what);
355355
}
356-
note_len += sprintf(note + note_len, "%.*s", url_len, url);
357-
fprintf(fp, "%s\t%s\t%s\n",
356+
note[note_len] = '\0';
357+
fprintf(fp, "%s\t%s\t%s",
358358
sha1_to_hex(commit ? commit->object.sha1 :
359359
rm->old_sha1),
360360
rm->merge ? "" : "not-for-merge",
361361
note);
362+
for (i = 0; i < url_len; ++i)
363+
if ('\n' == url[i])
364+
fputs("\\n", fp);
365+
else
366+
fputc(url[i], fp);
367+
fputc('\n', fp);
362368

363369
if (ref)
364370
rc |= update_local_ref(ref, what, note);

0 commit comments

Comments
 (0)