Fix a memory leak in "connect.c" and die if command too long.
Use "add_to_string" instead of "sq_quote" and "snprintf", so that there is no memory allocation and no memory leak. Also check if the command is too long to fit into the buffer and die if this is the case, instead of truncating it to the buffer size. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Christian Couder committed
Sep 11, 2006 at 07:04 UTC
0f503d77ac9032fbfbd5f3bacafeccbcf408b31f
1 file changed
+14
-3
connect.c
+14
-3
@@ -599,12 +599,13 @@ static void git_proxy_connect(int fd[2], char *host)
599
close(pipefd[1][0]);
600
}
601
602
+#define MAX_CMD_LEN 1024
603
+
604
/*
605
* Yeah, yeah, fixme. Need to pass in the heads etc.
606
*/
607
int git_connect(int fd[2], char *url, const char *prog)
608
{
607
- char command[1024];
609
char *host, *path = url;
610
char *end;
611
int c;
@@ -697,8 +698,18 @@ int git_connect(int fd[2], char *url, const char *prog)
698
if (pid < 0)
699
die("unable to fork");
700
if (!pid) {
700
- snprintf(command, sizeof(command), "%s %s", prog,
701
- sq_quote(path));
701
+ char command[MAX_CMD_LEN];
702
+ char *posn = command;
703
+ int size = MAX_CMD_LEN;
704
+ int of = 0;
705
+
706
+ of |= add_to_string(&posn, &size, prog, 0);
707
+ of |= add_to_string(&posn, &size, " ", 0);
708
+ of |= add_to_string(&posn, &size, path, 1);
709
+
710
+ if (of)
711
+ die("command line too long");
712
+
713
dup2(pipefd[1][0], 0);
714
dup2(pipefd[0][1], 1);
715
close(pipefd[0][0]);