{"thread":{"id":"6079","subject":"[PATCH] Keep \"git --git-dir\" from causing a bus error.","startedAt":"2006-12-22T13:56:25Z","lastAt":"2006-12-22T17:34:01Z","messageCount":3,"participants":["Brian Gernhardt","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"30057","messageId":"20061222135625.GA26084@179.242.249.10.in-addr.arpa","threadId":"6079","inReplyTo":null,"subject":"[PATCH] Keep \"git --git-dir\" from causing a bus error.","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2006-12-22T13:56:25Z","receivedAt":"2006-12-22T13:56:25Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"The option checking code for --git-dir had an off by 1 error that\nwould cause it to access uninitialized memory if it was the last\nargument.  This causes it to display an error and display the usage\nstring instead.\n\nSigned-off-by: Brian Gernhardt <benji@silverinsanity.com>\n---\n\n I would have made this display the git directory, but the code to\n do that seems to be unique to rev-parse and involve more set up than is\n done at the time the option is parsed.\n\n git.c |   13 ++++++++-----\n 1 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 73cf4d4..2b3c9f9 100644\n--- a/git.c\n+++ b/git.c\n@@ -59,11 +59,14 @@ static int handle_options(const char*** argv, int* argc)\n \t\t} else if (!strcmp(cmd, \"-p\") || !strcmp(cmd, \"--paginate\")) {\n \t\t\tsetup_pager();\n \t\t} else if (!strcmp(cmd, \"--git-dir\")) {\n-\t\t\tif (*argc < 1)\n-\t\t\t\treturn -1;\n-\t\t\tsetenv(\"GIT_DIR\", (*argv)[1], 1);\n-\t\t\t(*argv)++;\n-\t\t\t(*argc)--;\n+\t\t\tif (*argc < 2) {\n+\t\t\t\tfprintf(stderr, \"No directory given for --git-dir.\\n\" );\n+\t\t\t\tusage(git_usage_string);\n+\t\t\t} else {\n+\t\t\t\tsetenv(\"GIT_DIR\", (*argv)[1], 1);\n+\t\t\t\t(*argv)++;\n+\t\t\t\t(*argc)--;\n+\t\t\t}\n \t\t} else if (!strncmp(cmd, \"--git-dir=\", 10)) {\n \t\t\tsetenv(\"GIT_DIR\", cmd + 10, 1);\n \t\t} else if (!strcmp(cmd, \"--bare\")) {\n-- \n1.4.4.GIT\n"},{"id":"30065","messageId":"Pine.LNX.4.63.0612221708070.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6079","inReplyTo":"20061222135625.GA26084@179.242.249.10.in-addr.arpa","subject":"Re: [PATCH] Keep \"git --git-dir\" from causing a bus error.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-22T16:08:53Z","receivedAt":"2006-12-22T16:08:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 22 Dec 2006, Brian Gernhardt wrote:\n\n> diff --git a/git.c b/git.c\n> index 73cf4d4..2b3c9f9 100644\n> --- a/git.c\n> +++ b/git.c\n> @@ -59,11 +59,14 @@ static int handle_options(const char*** argv, int* argc)\n>  \t\t} else if (!strcmp(cmd, \"-p\") || !strcmp(cmd, \"--paginate\")) {\n>  \t\t\tsetup_pager();\n>  \t\t} else if (!strcmp(cmd, \"--git-dir\")) {\n> -\t\t\tif (*argc < 1)\n> -\t\t\t\treturn -1;\n> -\t\t\tsetenv(\"GIT_DIR\", (*argv)[1], 1);\n> -\t\t\t(*argv)++;\n> -\t\t\t(*argc)--;\n> +\t\t\tif (*argc < 2) {\n> +\t\t\t\tfprintf(stderr, \"No directory given for --git-dir.\\n\" );\n> +\t\t\t\tusage(git_usage_string);\n\nUsage already exits, so you do not need this:\n\n> +\t\t\t} else {\n\nCiao,\nDscho\n"},{"id":"30072","messageId":"2E577524-FAFC-4A9C-809D-B3698682FDEB@silverinsanity.com","threadId":"6079","inReplyTo":"Pine.LNX.4.63.0612221708070.19693@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Keep \"git --git-dir\" from causing a bus error.","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2006-12-22T17:34:01Z","receivedAt":"2006-12-22T17:34:01Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Dec 22, 2006, at 11:08 AM, Johannes Schindelin wrote:\n\n>> +\t\t\t\tfprintf(stderr, \"No directory given for --git-dir.\\n\" );\n>> +\t\t\t\tusage(git_usage_string);\n>\n> Usage already exits, so you do not need this:\n>\n>> +\t\t\t} else {\n\nI suppose not.  It came out of a) habit and b) experiments with  \nthings that did not exit.\n\n~~ Brian\n"}]}