summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-01-15 21:49:40 -0600
committerJunio C Hamano <gitster@pobox.com>2011-01-18 10:18:25 -0800
commit60a2e3320f3030d7c1f453a8cadafad7012fd820 (patch)
tree9fa1a38c83a433cf1afa54723afbfe1212fd6218
parent898243b82db862867106854ad10794e74c215e49 (diff)
downloadgit-60a2e3320f3030d7c1f453a8cadafad7012fd820.tar.gz
remote-ext: do not segfault for blank lines
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/remote-ext.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/builtin/remote-ext.c b/builtin/remote-ext.c
index 1f773171cb..ea71977c83 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");