Skip to contentSkip to conversation

upload-pack: don't send null character in abort message to the client

PATCH In review SZEDER Gábor 2 participants 2 messages Feb 25, 2024 – Feb 26, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 upload-pack: don't send null character in abort message to the client

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.

---
 upload-pack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
upload-pack.c +1 -1
index 2537affa90..6e0d441ef5 100644
@@ -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);
 }
Signature · 1 line
2.44.0.rc1.366.g26e5fbbdb0
#1 lore raw
Quoted 3 lines · SZEDER Gábor

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.

It is so so old that makes me wonder if it is safe to "fix" it, but I cannot think of a sensible way to write a third-party client that may have been working fine and would break when this fix is made.

Quoted 28 lines

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.

---
 upload-pack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
upload-pack.c +1 -1
index 2537affa90..6e0d441ef5 100644
@@ -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);
 }