Skip to content

Commit 60a2e33

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 898243b commit 60a2e33

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

builtin/remote-ext.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,16 @@ static int command_loop(const char *child)
212212
char buffer[MAXCOMMAND];
213213

214214
while (1) {
215-
size_t length;
215+
size_t i;
216216
if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
217217
if (ferror(stdin))
218218
die("Comammand input error");
219219
exit(0);
220220
}
221221
/* Strip end of line characters. */
222-
length = strlen(buffer);
223-
while (isspace((unsigned char)buffer[length - 1]))
224-
buffer[--length] = 0;
222+
i = strlen(buffer);
223+
while (i > 0 && isspace(buffer[i - 1]))
224+
buffer[--i] = 0;
225225

226226
if (!strcmp(buffer, "capabilities")) {
227227
printf("*connect\n\n");

0 commit comments

Comments
 (0)