ssh-upload: prevent buffer overrun
[gitweb.git] / git.c
diff --git a/git.c b/git.c
index 016ee8adb730ea7c390dcb84dcbbafda7936f2d5..bf55499dc3d555dfaa853b0c6e4aec5439c3532e 100644 (file)
--- a/git.c
+++ b/git.c
@@ -1,20 +1,8 @@
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdarg.h>
-#include "git-compat-util.h"
+#include "builtin.h"
 #include "exec_cmd.h"
 #include "cache.h"
 #include "quote.h"
 
-#include "builtin.h"
-
 const char git_usage_string[] =
        "git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]";
 
@@ -71,16 +59,18 @@ static int handle_options(const char*** argv, int* argc)
                } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
                        setup_pager();
                } else if (!strcmp(cmd, "--git-dir")) {
-                       if (*argc < 1)
-                               return -1;
-                       setenv("GIT_DIR", (*argv)[1], 1);
+                       if (*argc < 2) {
+                               fprintf(stderr, "No directory given for --git-dir.\n" );
+                               usage(git_usage_string);
+                       }
+                       setenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1);
                        (*argv)++;
                        (*argc)--;
                } else if (!strncmp(cmd, "--git-dir=", 10)) {
-                       setenv("GIT_DIR", cmd + 10, 1);
+                       setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
                } else if (!strcmp(cmd, "--bare")) {
-                       static char git_dir[1024];
-                       setenv("GIT_DIR", getcwd(git_dir, 1024), 1);
+                       static char git_dir[PATH_MAX+1];
+                       setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 1);
                } else {
                        fprintf(stderr, "Unknown option: %s\n", cmd);
                        usage(git_usage_string);
@@ -241,6 +231,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "get-tar-commit-id", cmd_get_tar_commit_id },
                { "grep", cmd_grep, RUN_SETUP },
                { "help", cmd_help },
+               { "init", cmd_init_db },
                { "init-db", cmd_init_db },
                { "log", cmd_log, RUN_SETUP | USE_PAGER },
                { "ls-files", cmd_ls_files, RUN_SETUP },
@@ -256,7 +247,9 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "prune-packed", cmd_prune_packed, RUN_SETUP },
                { "push", cmd_push, RUN_SETUP },
                { "read-tree", cmd_read_tree, RUN_SETUP },
+               { "reflog", cmd_reflog, RUN_SETUP },
                { "repo-config", cmd_repo_config },
+               { "rerere", cmd_rerere, RUN_SETUP },
                { "rev-list", cmd_rev_list, RUN_SETUP },
                { "rev-parse", cmd_rev_parse, RUN_SETUP },
                { "rm", cmd_rm, RUN_SETUP },