From 360204c324ca9178e2bcb4d75f3986201f8ac7e1 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Mon, 17 Apr 2006 13:41:49 +0200 Subject: Allow empty lines in info/grafts In addition to the existing comment support, that just allows the user to use a convention that works pretty much everywhere else. Signed-off-by: Yann Dirson Signed-off-by: Junio C Hamano --- commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: -- cgit v1.2.3 From da2a95b2a86e8b140d6c5413ea4307e395884135 Mon Sep 17 00:00:00 2001 From: "Serge E. Hallyn" Date: Mon, 17 Apr 2006 10:14:47 -0500 Subject: 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 Signed-off-by: Junio C Hamano --- connect.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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; } -- cgit v1.2.3 From 310f8b5b6d17d805cb9a59a20ba747d5f093604a Mon Sep 17 00:00:00 2001 From: "Serge E. Hallyn" Date: Mon, 17 Apr 2006 10:14:47 -0500 Subject: cleanups: Remove unused vars from combine-diff.c Mod_type in particular sure looks like it wants to be used, but isn't. Signed-off-by: Serge E. Hallyn Signed-off-by: Junio C Hamano --- combine-diff.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 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) -- cgit v1.2.3 From ecc13e73cf96cb14e2403be6538593a167d7ea23 Mon Sep 17 00:00:00 2001 From: "Serge E. Hallyn" Date: Mon, 17 Apr 2006 10:14:48 -0500 Subject: cleanups: Remove impossible case in quote.c The switch is inside an if statement which is false if the character is ' '. Either the if should be <=' ' instead of <' ', or the case should be removed as it could be misleading. Signed-off-by: Serge E. Hallyn Signed-off-by: Junio C Hamano --- quote.c | 2 -- 1 file changed, 2 deletions(-) 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(); -- cgit v1.2.3 From dafc88b136b508c1c08129b756b6ba23b7c9d341 Mon Sep 17 00:00:00 2001 From: "Serge E. Hallyn" Date: Mon, 17 Apr 2006 10:14:48 -0500 Subject: cleanups: prevent leak of two strduped strings in config.c Config_filename and lockfile are strduped and then leaked in git_config_set_multivar. Signed-off-by: Serge E. Hallyn Signed-off-by: Junio C Hamano --- config.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) 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; } -- cgit v1.2.3 From bb996614de4fddfa73286479f3c6a901107a2629 Mon Sep 17 00:00:00 2001 From: "Serge E. Hallyn" Date: Mon, 17 Apr 2006 10:14:48 -0500 Subject: cleanups: remove unused variable from exec_cmd.c Not sure whether it should be removed, or whether execv_git_cmd() should return it rather than -1 at bottom. Signed-off-by: Serge E. Hallyn Signed-off-by: Junio C Hamano --- exec_cmd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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; -- cgit v1.2.3 From 2855d58079cd56361879cc03f7c769409bb445e5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 17 Apr 2006 17:46:07 -0700 Subject: packed_object_info_detail(): check for corrupt packfile. Serge E. Hallyn noticed that we compute how many input bytes are still left, but did not use it for sanity checking. Signed-off-by: Junio C Hamano --- sha1_file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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; -- cgit v1.2.3