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>
This commit is contained in:
parent
898243b82d
commit
60a2e3320f
@ -212,16 +212,16 @@ static int command_loop(const char *child)
|
|||||||
char buffer[MAXCOMMAND];
|
char buffer[MAXCOMMAND];
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
size_t length;
|
size_t i;
|
||||||
if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
|
if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
|
||||||
if (ferror(stdin))
|
if (ferror(stdin))
|
||||||
die("Comammand input error");
|
die("Comammand input error");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
/* Strip end of line characters. */
|
/* Strip end of line characters. */
|
||||||
length = strlen(buffer);
|
i = strlen(buffer);
|
||||||
while (isspace((unsigned char)buffer[length - 1]))
|
while (i > 0 && isspace(buffer[i - 1]))
|
||||||
buffer[--length] = 0;
|
buffer[--i] = 0;
|
||||||
|
|
||||||
if (!strcmp(buffer, "capabilities")) {
|
if (!strcmp(buffer, "capabilities")) {
|
||||||
printf("*connect\n\n");
|
printf("*connect\n\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user