@matheusbsbs / matheus-bagliano / commits / 60a2e3320f
Fork 0

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>

Jonathan Nieder committed Jan 15, 2011 at 21:49 UTC 60a2e3320f3030d7c1f453a8cadafad7012fd820
1 file changed +4 -4
builtin/remote-ext.c
+4 -4
@@ -212,16 +212,16 @@ static int command_loop(const char *child)
212 char buffer[MAXCOMMAND];
213
214 while (1) {
215 - size_t length;
215 + size_t i;
216 if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
217 if (ferror(stdin))
218 die("Comammand input error");
219 exit(0);
220 }
221 /* 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;
225
226 if (!strcmp(buffer, "capabilities")) {
227 printf("*connect\n\n");