git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] remote-ext: do not segfault for blank lines
Date: Sat, 15 Jan 2011 21:49:40 -0600	[thread overview]
Message-ID: <20110116034940.GA29072@burratino> (raw)
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

      parent reply	other threads:[~2011-01-16  3:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-12 16:39 [RFC PATCH v7 0/3] git-remote-fd & git-remote-ext Ilari Liusvaara
2010-10-12 16:39 ` [RFC PATCH v7 1/3] Add bidirectional_transfer_loop() Ilari Liusvaara
2010-10-12 16:39 ` [RFC PATCH v7 2/3] git-remote-fd Ilari Liusvaara
2010-10-13 23:33   ` Junio C Hamano
2010-10-12 16:39 ` [RFC PATCH v7 3/3] git-remote-ext Ilari Liusvaara
2010-10-13 23:32   ` Junio C Hamano
2011-01-16  3:49   ` Jonathan Nieder [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110116034940.GA29072@burratino \
    --to=jrnieder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ilari.liusvaara@elisanet.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).