git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 3/3] sideband: add defense against packets missing a band designator

From
Jeff King <peff@peff.net>
Date
Oct 23, 2020, 08:48 UTC
Message-ID
<20201023084827.GE4012156@coredump.intra.peff.net>
In-Reply-To
<c61e560451c4d7f101a23acec69117ddac563330.1603136143.git.gitgitgadget@gmail.com>
On Mon, Oct 19, 2020 at 07:35:42PM +0000, Johannes Schindelin via GitGitGadget wrote:
Show 16 quoted lines
> diff --git a/pkt-line.c b/pkt-line.c
> index 657a702927..f72048f623 100644
> --- a/pkt-line.c
> +++ b/pkt-line.c
> @@ -461,8 +461,10 @@ int recv_sideband(const char *me, int in_stream, int out)
>  	enum sideband_type sideband_type;
>  
>  	while (1) {
> -		len = packet_read(in_stream, NULL, NULL, buf, LARGE_PACKET_MAX,
> -				  0);
> +		int status = packet_read_with_status(in_stream, NULL, NULL, buf,
> +						     LARGE_PACKET_MAX, &len, 0);
> +		if (!len && status == PACKET_READ_NORMAL)
> +			BUG("missing band designator");
>  		if (!demultiplex_sideband(me, buf, len, 0, &scratch,
>  					  &sideband_type))

I also wonder if this status-check should be pushed down into demultiplex_sideband() by passing "status", for two reasons:

  1. So we don't have to repeat it (though it isn't that big)
  2. The other half of this weirdness is that if we get an early EOF,
     we'll hit the "missing sideband designator" die() message. But
     that's not really what happened; we probably got a network hangup.
     And we could distinguish that case by checking for status ==
     PACKET_READ_EOF and provide a better message.
Something like this (completely untested):
diff --git a/sideband.c b/sideband.c
index 0a60662fa6..6ad15ed581 100644
--- a/sideband.c
+++ b/sideband.c
@@ -115,6 +115,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
 #define DUMB_SUFFIX "        "
 
 int demultiplex_sideband(const char *me, char *buf, int len,
+			 enum packet_read_status status,
 			 int die_on_error,
 			 struct strbuf *scratch,
 			 enum sideband_type *sideband_type)
@@ -130,17 +131,29 @@ int demultiplex_sideband(const char *me, char *buf, int len,
 			suffix = DUMB_SUFFIX;
 	}
 
-	if (len == 0) {
-		*sideband_type = SIDEBAND_FLUSH;
-		goto cleanup;
-	}
-	if (len < 1) {
+	if (status == PACKET_READ_EOF) {
 		strbuf_addf(scratch,
-			    "%s%s: protocol error: no band designator",
+			    "%s%s: protocol error: eof while reading packet",
 			    scratch->len ? "\n" : "", me);
 		*sideband_type = SIDEBAND_PROTOCOL_ERROR;
 		goto cleanup;
 	}
+
+	if (len < 0)
+		BUG("negative length on non-eof packet read");
+
+	if (len == 0) {
+		if (status == PACKET_READ_NORMAL) {
+			strbuf_addf(scratch,
+				    "%s%s protocol error: no band designator",
+				    scratch->len ? "\n" : "", me);
+			*sideband_type = SIDEBAND_PROTOCOL_ERROR;
+		} else {
+			*sideband_type = SIDEBAND_FLUSH;
+		}
+		goto cleanup;
+	}
+
 	band = buf[0] & 0xff;
 	buf[len] = '\0';
 	len--;
Previous: Junio C HamanoNext: Johannes Schindelin
Message 18 of 33 in “t5500.43: make the check a bit more robust”
  1. t5500.43: make the check a bit more robustJohannes Schindelin via GitGitGadget, Oct 13, 2020
  2. Junio C HamanoOct 13, 2020
  3. Jeff KingOct 13, 2020
  4. Junio C HamanoOct 13, 2020
  5. Jeff KingOct 13, 2020
  6. Johannes SchindelinOct 17, 2020
  7. Johannes SchindelinOct 17, 2020
  8. 0/3 Work around flakiness in t5500.43Johannes Schindelin via GitGitGadget, Oct 19, 2020
  9. 1/3 sideband: avoid reporting incomplete sideband messagesJohannes Schindelin via GitGitGadget, Oct 19, 2020
  10. Junio C HamanoOct 20, 2020
  11. Johannes SchindelinOct 20, 2020
  12. Junio C HamanoOct 20, 2020
  13. 2/3 sideband: report unhandled incomplete sideband messages as bugsJohannes Schindelin via GitGitGadget, Oct 19, 2020
  14. 3/3 sideband: add defense against packets missing a band designatorJohannes Schindelin via GitGitGadget, Oct 19, 2020
  15. Junio C HamanoOct 20, 2020
  16. Jeff KingOct 23, 2020
  17. Junio C HamanoOct 23, 2020
  18. Jeff KingOct 23, 2020
  19. Johannes SchindelinOct 23, 2020
  20. Jeff KingOct 23, 2020
  21. Johannes SchindelinOct 26, 2020
  22. 0/2 Work around flakiness in t5500.43Johannes Schindelin via GitGitGadget, Oct 26, 2020
  23. 1/2 sideband: avoid reporting incomplete sideband messagesJohannes Schindelin via GitGitGadget, Oct 26, 2020
  24. 2/2 sideband: report unhandled incomplete sideband messages as bugsJohannes Schindelin via GitGitGadget, Oct 26, 2020
  25. Junio C HamanoOct 26, 2020
  26. sideband: diagnose more incoming packet anomaliesJeff King, Oct 27, 2020
  27. Jeff KingOct 27, 2020
  28. Junio C HamanoOct 27, 2020
  29. Jeff KingOct 27, 2020
  30. Junio C HamanoOct 27, 2020
  31. Jeff KingOct 28, 2020
  32. Jeff KingOct 27, 2020
  33. Junio C HamanoOct 27, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.