summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <junkio@cox.net>2006-04-17 23:15:20 -0700
committerLibravatar Junio C Hamano <junkio@cox.net>2006-04-17 23:15:20 -0700
commite5de825fda5795c2607ae870fcc4369db1ae77c2 (patch)
tree63e7ed4fe514a415aee3aec516ba7b3e8e7beb59
parentMerge branch 'jc/boundary' into next (diff)
parentpacked_object_info_detail(): check for corrupt packfile. (diff)
downloadtgif-e5de825fda5795c2607ae870fcc4369db1ae77c2.tar.xz
Merge branch 'master' into next
* master: packed_object_info_detail(): check for corrupt packfile. cleanups: remove unused variable from exec_cmd.c cleanups: prevent leak of two strduped strings in config.c cleanups: Remove impossible case in quote.c cleanups: Remove unused vars from combine-diff.c cleanups: Fix potential bugs in connect.c Allow empty lines in info/grafts
-rw-r--r--combine-diff.c12
-rw-r--r--commit.c2
-rw-r--r--config.c39
-rw-r--r--connect.c18
-rw-r--r--exec_cmd.c4
-rw-r--r--quote.c2
-rw-r--r--sha1_file.c6
7 files changed, 50 insertions, 33 deletions
diff --git a/combine-diff.c b/combine-diff.c
index 9bd27f82ec..9445e86c2f 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -589,7 +589,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
struct diff_options *opt)
{
unsigned long result_size, cnt, lno;
- char *result, *cp, *ep;
+ char *result, *cp;
struct sline *sline; /* survived lines */
int mode_differs = 0;
int i, show_hunks, shown_header = 0;
@@ -641,7 +641,6 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
cnt++; /* incomplete line */
sline = xcalloc(cnt+2, sizeof(*sline));
- ep = result;
sline[0].bol = result;
for (lno = 0; lno <= cnt + 1; lno++) {
sline[lno].lost_tail = &sline[lno].lost_head;
@@ -752,7 +751,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
static void show_raw_diff(struct combine_diff_path *p, int num_parent, const char *header, struct diff_options *opt)
{
- int i, offset, mod_type = 'A';
+ int i, offset;
const char *prefix;
int line_termination, inter_name_termination;
@@ -764,13 +763,6 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
if (header)
printf("%s%c", header, line_termination);
- for (i = 0; i < num_parent; i++) {
- if (p->parent[i].mode)
- mod_type = 'M';
- }
- if (!p->mode)
- mod_type = 'D';
-
if (opt->output_format == DIFF_FORMAT_RAW) {
offset = strlen(COLONS) - num_parent;
if (offset < 0)
diff --git a/commit.c b/commit.c
index 05c4c923fa..2717dd81c3 100644
--- a/commit.c
+++ b/commit.c
@@ -160,7 +160,7 @@ struct commit_graft *read_graft_line(char *buf, int len)
if (buf[len-1] == '\n')
buf[--len] = 0;
- if (buf[0] == '#')
+ if (buf[0] == '#' || buf[0] == '\0')
return NULL;
if ((len + 1) % 41) {
bad_graft_data:
diff --git a/config.c b/config.c
index 95ec34923d..7ea8a7369a 100644
--- a/config.c
+++ b/config.c
@@ -420,6 +420,7 @@ int git_config_set_multivar(const char* key, const char* value,
{
int i;
int fd, in_fd;
+ int ret;
char* config_filename = strdup(git_path("config"));
char* lock_file = strdup(git_path("config.lock"));
const char* last_dot = strrchr(key, '.');
@@ -429,9 +430,10 @@ int git_config_set_multivar(const char* key, const char* value,
* key name separated by a dot, we have to know where the dot is.
*/
- if (last_dot == NULL) {
+ if (last_dot == NULL) {
fprintf(stderr, "key does not contain a section: %s\n", key);
- return 2;
+ ret = 2;
+ goto out_free;
}
store.baselen = last_dot - key;
@@ -447,7 +449,8 @@ int git_config_set_multivar(const char* key, const char* value,
(i == store.baselen+1 && !isalpha(key[i])))) {
fprintf(stderr, "invalid key: %s\n", key);
free(store.key);
- return 1;
+ ret = 1;
+ goto out_free;
} else
store.key[i] = tolower(key[i]);
store.key[i] = 0;
@@ -460,7 +463,8 @@ int git_config_set_multivar(const char* key, const char* value,
if (fd < 0) {
fprintf(stderr, "could not lock config file\n");
free(store.key);
- return -1;
+ ret = -1;
+ goto out_free;
}
/*
@@ -475,13 +479,15 @@ int git_config_set_multivar(const char* key, const char* value,
strerror(errno));
close(fd);
unlink(lock_file);
- return 3; /* same as "invalid config file" */
+ ret = 3; /* same as "invalid config file" */
+ goto out_free;
}
/* if nothing to unset, error out */
if (value == NULL) {
close(fd);
unlink(lock_file);
- return 5;
+ ret = 5;
+ goto out_free;
}
store.key = (char*)key;
@@ -507,7 +513,8 @@ int git_config_set_multivar(const char* key, const char* value,
fprintf(stderr, "Invalid pattern: %s\n",
value_regex);
free(store.value_regex);
- return 6;
+ ret = 6;
+ goto out_free;
}
}
@@ -528,7 +535,8 @@ int git_config_set_multivar(const char* key, const char* value,
regfree(store.value_regex);
free(store.value_regex);
}
- return 3;
+ ret = 3;
+ goto out_free;
}
free(store.key);
@@ -542,7 +550,8 @@ int git_config_set_multivar(const char* key, const char* value,
(store.seen > 1 && multi_replace == 0)) {
close(fd);
unlink(lock_file);
- return 5;
+ ret = 5;
+ goto out_free;
}
fstat(in_fd, &st);
@@ -593,10 +602,18 @@ int git_config_set_multivar(const char* key, const char* value,
if (rename(lock_file, config_filename) < 0) {
fprintf(stderr, "Could not rename the lock file?\n");
- return 4;
+ ret = 4;
+ goto out_free;
}
- return 0;
+ ret = 0;
+
+out_free:
+ if (config_filename)
+ free(config_filename);
+ if (lock_file)
+ free(lock_file);
+ return ret;
}
diff --git a/connect.c b/connect.c
index 3f2d65c313..6a8f8a6a24 100644
--- a/connect.c
+++ b/connect.c
@@ -74,7 +74,7 @@ int get_ack(int fd, unsigned char *result_sha1)
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, const char *prog)
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, const char *prog)
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, const char *prog)
fd[1] = pipefd[1][1];
close(pipefd[0][1]);
close(pipefd[1][0]);
+ if (free_path)
+ free(path);
return pid;
}
diff --git a/exec_cmd.c b/exec_cmd.c
index 590e738969..44bb2f23de 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -32,7 +32,7 @@ const char *git_exec_path(void)
int execv_git_cmd(const char **argv)
{
char git_command[PATH_MAX + 1];
- int len, err, i;
+ int len, i;
const char *paths[] = { current_exec_path,
getenv("GIT_EXEC_PATH"),
builtin_exec_path };
@@ -85,8 +85,6 @@ int execv_git_cmd(const char **argv)
/* execve() can only ever return if it fails */
execve(git_command, (char **)argv, environ);
- err = errno;
-
argv[0] = tmp;
}
return -1;
diff --git a/quote.c b/quote.c
index 7218a7080d..06792d47c3 100644
--- a/quote.c
+++ b/quote.c
@@ -144,8 +144,6 @@ static int quote_c_style_counted(const char *name, int namelen,
case '\\': /* fallthru */
case '"': EMITQ(); break;
- case ' ':
- break;
default:
/* octal */
EMITQ();
diff --git a/sha1_file.c b/sha1_file.c
index e3d011309a..f2d33afb27 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -874,17 +874,19 @@ void packed_object_info_detail(struct pack_entry *e,
unsigned char *base_sha1)
{
struct packed_git *p = e->p;
- unsigned long offset, left;
+ unsigned long offset;
unsigned char *pack;
enum object_type kind;
offset = unpack_object_header(p, e->offset, &kind, size);
pack = p->pack_base + offset;
- left = p->pack_size - offset;
if (kind != OBJ_DELTA)
*delta_chain_length = 0;
else {
unsigned int chain_length = 0;
+ if (p->pack_size <= offset + 20)
+ die("pack file %s records an incomplete delta base",
+ p->pack_name);
memcpy(base_sha1, pack, 20);
do {
struct pack_entry base_ent;