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

[PATCH] remote-ext: do not segfault for blank lines

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jan 16, 2011, 03:49 UTC
Message-ID
<20110116034940.GA29072@burratino>
In-Reply-To
<1286901583-30088-4-git-send-email-ilari.liusvaara@elisanet.fi>

Instead of stripping space characters past the beginning of the line and overflowing a buffer, stop at the beginning of the line (mimicking the corresponding fix in remote-fd).

The argument to isspace does not need to be cast explicitly because git isspace takes care of that already.

Noticed-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 builtin/remote-ext.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/builtin/remote-ext.c b/builtin/remote-ext.c
index 1f77317..ea71977 100644
--- a/builtin/remote-ext.c
+++ b/builtin/remote-ext.c
@@ -212,16 +212,16 @@ static int command_loop(const char *child)
 	char buffer[MAXCOMMAND];
 
 	while (1) {
-		size_t length;
+		size_t i;
 		if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
 			if (ferror(stdin))
 				die("Comammand input error");
 			exit(0);
 		}
 		/* Strip end of line characters. */
-		length = strlen(buffer);
-		while (isspace((unsigned char)buffer[length - 1]))
-			buffer[--length] = 0;
+		i = strlen(buffer);
+		while (i > 0 && isspace(buffer[i - 1]))
+			buffer[--i] = 0;
 
 		if (!strcmp(buffer, "capabilities")) {
 			printf("*connect\n\n");
-- 
1.7.4.rc2
Previous: Junio C Hamano
Message 7 of 7 in “git-remote-fd & git-remote-ext”
  1. 0/3 git-remote-fd & git-remote-extIlari Liusvaara, Oct 12, 2010
  2. 1/3 Add bidirectional_transfer_loop()Ilari Liusvaara, Oct 12, 2010
  3. 2/3 git-remote-fdIlari Liusvaara, Oct 12, 2010
  4. Junio C HamanoOct 13, 2010
  5. 3/3 git-remote-extIlari Liusvaara, Oct 12, 2010
  6. Junio C HamanoOct 13, 2010
  7. remote-ext: do not segfault for blank linesJonathan Nieder, Jan 16, 2011

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.