X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=git.c;h=0975fc7ac2673c952bfdf1372d2e22c001ecf7d5;hb=8bf14d6ef9245f3b81d24cb7725a868f62343277;hp=bdd3f8d01c0be5edeccf8b99c98a1cff5d70dbc2;hpb=302ebfe52192fff9a2c1c612dff22325fd073acc;p=git.git diff --git a/git.c b/git.c index bdd3f8d0..0975fc7a 100644 --- a/git.c +++ b/git.c @@ -13,6 +13,10 @@ # define PATH_MAX 4096 #endif +#ifdef NO_SETENV +extern int gitsetenv(const char *, const char *, int); +#endif + static const char git_usage[] = "Usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--help] COMMAND [ ARGS ]"; @@ -188,7 +192,6 @@ static void prepend_to_path(const char *dir, int len) path_len = len + strlen(old_path) + 1; path = malloc(path_len + 1); - path[path_len + 1] = '\0'; memcpy(path, dir, len); path[len] = ':'; @@ -273,7 +276,7 @@ int main(int argc, char **argv, char **envp) while (!strncmp(exec_path, "./", 2)) { exec_path += 2; while (*exec_path == '/') - *exec_path++; + exec_path++; } snprintf(git_command + len, sizeof(git_command) - len, "/%s", exec_path); @@ -283,16 +286,21 @@ int main(int argc, char **argv, char **envp) len = strlen(git_command); prepend_to_path(git_command, len); - strncat(&git_command[len], "/git-", sizeof(git_command) - len); - len += 5; - strncat(&git_command[len], argv[i], sizeof(git_command) - len); - - if (access(git_command, X_OK)) - usage(exec_path, "'%s' is not a git-command", argv[i]); + len += snprintf(git_command + len, sizeof(git_command) - len, + "/git-%s", argv[i]); + if (sizeof(git_command) <= len) { + fprintf(stderr, "git: command name given is too long (%d)\n", len); + exit(1); + } /* execve() can only ever return if it fails */ execve(git_command, &argv[i], envp); - printf("Failed to run command '%s': %s\n", git_command, strerror(errno)); + + if (errno == ENOENT) + usage(exec_path, "'%s' is not a git-command", argv[i]); + + fprintf(stderr, "Failed to run command '%s': %s\n", + git_command, strerror(errno)); return 1; }