From: "Serge E. Hallyn" <serue@us.ibm.com>
To: git@vger.kernel.org
Subject: [PATCH 2/7] cleanups: Fix potential bugs in connect.c
Date: Mon, 17 Apr 2006 10:14:47 -0500 (CDT) [thread overview]
Message-ID: <20060417151447.E2A5919B90F@sergelap.hallyn.com> (raw)
In-Reply-To: 20060417145148.2F3CB19C90D@sergelap.hallyn.com
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 <serue@us.ibm.com>
---
connect.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
1b4f45918d8c1f7d579840c7bb1fe3fe1967b6c5
diff --git a/connect.c b/connect.c
index 3f2d65c..6a8f8a6 100644
--- a/connect.c
+++ b/connect.c
@@ -74,7 +74,7 @@ int get_ack(int fd, unsigned char *resul
line[--len] = 0;
if (!strcmp(line, "NAK"))
return 0;
- if (!strncmp(line, "ACK ", 3)) {
+ if (!strncmp(line, "ACK ", 4)) {
if (!get_sha1_hex(line+4, result_sha1)) {
if (strstr(line+45, "continue"))
return 2;
@@ -567,6 +567,7 @@ int git_connect(int fd[2], char *url, co
int pipefd[2][2];
pid_t pid;
enum protocol protocol = PROTO_LOCAL;
+ int free_path = 0;
host = strstr(url, "://");
if(host) {
@@ -610,16 +611,23 @@ int git_connect(int fd[2], char *url, co
char *ptr = path;
if (path[1] == '~')
path++;
- else
+ else {
path = strdup(ptr);
+ free_path = 1;
+ }
*ptr = '\0';
}
if (protocol == PROTO_GIT) {
+ int ret;
if (git_use_proxy(host))
- return git_proxy_connect(fd, prog, host, path);
- return git_tcp_connect(fd, prog, host, path);
+ ret = git_proxy_connect(fd, prog, host, path);
+ else
+ ret = git_tcp_connect(fd, prog, host, path);
+ if (free_path)
+ free(path);
+ return ret;
}
if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
@@ -659,6 +667,8 @@ int git_connect(int fd[2], char *url, co
fd[1] = pipefd[1][1];
close(pipefd[0][1]);
close(pipefd[1][0]);
+ if (free_path)
+ free(path);
return pid;
}
--
1.2.5
next prev parent reply other threads:[~2006-04-17 15:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-17 15:14 [PATCH 0/7] cleanups: intro Serge E. Hallyn
2006-04-17 15:14 ` [PATCH 3/7] cleanups: Remove unused vars from combine-diff.c Serge E. Hallyn
2006-04-17 15:14 ` Serge E. Hallyn [this message]
2006-04-17 15:14 ` [PATCH 1/7] cleanups: Fix resource leak and buffer overrun in daemon.c Serge E. Hallyn
2006-04-17 21:42 ` Junio C Hamano
2006-04-18 13:11 ` Serge E. Hallyn
2006-04-18 19:32 ` Junio C Hamano
2006-04-17 15:14 ` [PATCH 5/7] cleanups: Remove unused variable from sha1_file.c Serge E. Hallyn
2006-04-17 21:42 ` Junio C Hamano
2006-04-17 15:14 ` [PATCH 4/7] cleanups: Remove impossible case in quote.c Serge E. Hallyn
2006-04-17 15:14 ` [PATCH 6/7] cleanups: prevent leak of two strduped strings in config.c Serge E. Hallyn
2006-04-17 15:14 ` [PATCH 7/7] cleanups: remove unused variable from exec_cmd.c Serge E. Hallyn
2006-04-17 21:42 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060417151447.E2A5919B90F@sergelap.hallyn.com \
--to=serue@us.ibm.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox