Skip to content

Commit

Permalink
remote-ext: do not segfault for blank lines
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Jan 18, 2011
1 parent 898243b commit 60a2e33
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions builtin/remote-ext.c
Original file line number Diff line number Diff line change
@@ -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");

0 comments on commit 60a2e33

Please sign in to comment.