]> git.ipfire.org Git - thirdparty/git.git/commitdiff
upload-pack: don't send null character in abort message to the client
authorSZEDER Gábor <szeder.dev@gmail.com>
Sun, 25 Feb 2024 18:34:52 +0000 (19:34 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Feb 2024 17:49:08 +0000 (09:49 -0800)
Since 583b7ea31b (upload-pack/fetch-pack: support side-band
communication, 2006-06-21) the abort message sent by upload-pack in
case of possible repository corruption ends with a null character.
This can be seen in several test cases in 't5530-upload-pack-error.sh'
where 'grep <pattern> output.err' often reports "Binary file
output.err matches" because of that null character.

The reason for this is that the abort message is defined as a string
literal, and we pass its size to the send function as
sizeof(abort_msg), which also counts the terminating null character.

Use strlen() instead to avoid sending that terminating null character.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
upload-pack.c

index 2537affa90762228a19d305be749f410d5afb5dc..6e0d441ef523edaeca10ffdf2e13f8d52ee592d0 100644 (file)
@@ -463,7 +463,7 @@ static void create_pack_file(struct upload_pack_data *pack_data,
 
  fail:
        free(output_state);
-       send_client_data(3, abort_msg, sizeof(abort_msg),
+       send_client_data(3, abort_msg, strlen(abort_msg),
                         pack_data->use_sideband);
        die("git upload-pack: %s", abort_msg);
 }