Skip to content

Commit da2a95b

Browse files
Serge E. HallynJunio C Hamano
authored andcommitted
cleanups: Fix potential bugs in connect.c
The strncmp for ACK was ACK does not include the final space. Presumably either we should either remove the trailing space, or compare 4 chars (as this patch does). 'path' is sometimes strdup'ed, but never freed. Signed-off-by: Serge E. Hallyn <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6feba7c commit da2a95b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

connect.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int get_ack(int fd, unsigned char *result_sha1)
7474
line[--len] = 0;
7575
if (!strcmp(line, "NAK"))
7676
return 0;
77-
if (!strncmp(line, "ACK ", 3)) {
77+
if (!strncmp(line, "ACK ", 4)) {
7878
if (!get_sha1_hex(line+4, result_sha1)) {
7979
if (strstr(line+45, "continue"))
8080
return 2;
@@ -567,6 +567,7 @@ int git_connect(int fd[2], char *url, const char *prog)
567567
int pipefd[2][2];
568568
pid_t pid;
569569
enum protocol protocol = PROTO_LOCAL;
570+
int free_path = 0;
570571

571572
host = strstr(url, "://");
572573
if(host) {
@@ -610,16 +611,23 @@ int git_connect(int fd[2], char *url, const char *prog)
610611
char *ptr = path;
611612
if (path[1] == '~')
612613
path++;
613-
else
614+
else {
614615
path = strdup(ptr);
616+
free_path = 1;
617+
}
615618

616619
*ptr = '\0';
617620
}
618621

619622
if (protocol == PROTO_GIT) {
623+
int ret;
620624
if (git_use_proxy(host))
621-
return git_proxy_connect(fd, prog, host, path);
622-
return git_tcp_connect(fd, prog, host, path);
625+
ret = git_proxy_connect(fd, prog, host, path);
626+
else
627+
ret = git_tcp_connect(fd, prog, host, path);
628+
if (free_path)
629+
free(path);
630+
return ret;
623631
}
624632

625633
if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
@@ -659,6 +667,8 @@ int git_connect(int fd[2], char *url, const char *prog)
659667
fd[1] = pipefd[1][1];
660668
close(pipefd[0][1]);
661669
close(pipefd[1][0]);
670+
if (free_path)
671+
free(path);
662672
return pid;
663673
}
664674

0 commit comments

Comments
 (0)