git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Keep "git --git-dir" from causing a bus error.

From
Brian Gernhardt <benji@silverinsanity.com>
Date
Dec 22, 2006, 13:56 UTC
Message-ID
<20061222135625.GA26084@179.242.249.10.in-addr.arpa>

The option checking code for --git-dir had an off by 1 error that would cause it to access uninitialized memory if it was the last argument. This causes it to display an error and display the usage string instead.

Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>
---
 I would have made this display the git directory, but the code to
 do that seems to be unique to rev-parse and involve more set up than is
 done at the time the option is parsed.
 git.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/git.c b/git.c
index 73cf4d4..2b3c9f9 100644
--- a/git.c
+++ b/git.c
@@ -59,11 +59,14 @@ 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);
-			(*argv)++;
-			(*argc)--;
+			if (*argc < 2) {
+				fprintf(stderr, "No directory given for --git-dir.\n" );
+				usage(git_usage_string);
+			} else {
+				setenv("GIT_DIR", (*argv)[1], 1);
+				(*argv)++;
+				(*argc)--;
+			}
 		} else if (!strncmp(cmd, "--git-dir=", 10)) {
 			setenv("GIT_DIR", cmd + 10, 1);
 		} else if (!strcmp(cmd, "--bare")) {
-- 
1.4.4.GIT
Next: Johannes Schindelin
Message 1 of 3 in “Keep "git --git-dir" from causing a bus error.”
  1. Keep "git --git-dir" from causing a bus error.Brian Gernhardt, Dec 22, 2006
  2. Johannes SchindelinDec 22, 2006
  3. Brian GernhardtDec 22, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.