threads / patch / 38328

patchgit.c: prevent change of environment variables

Subject: [PATCH] git.c: prevent change of environment variables

## tl;dr

2 messages between Jan 10, 2015 and Jan 10, 2015. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Alexander Kuleshov· Jan 10, 2015, 12:53 UTC · lore
We can't change environment variables in aliases which doesn't start with '!'
* 'git --exec-path=path' changes $GIT_EXEC_PATH variable in
git_set_argv_exec_path
* 'git -p/--paginate' sets 'use_pager' to 1 and commit_pager_choice
will change $GIT_PAGER_IN_USE variable in setup_pager(void) from pager.c
* 'git -c' calls git_config_push_parameter which will change
$GIT_CONFIG_PARAMETERS variable
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 git.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
Show changes to git.c +8 −1
diff --git a/git.c b/git.c
index c9bec99..3e87f05 100644
--- a/git.c
+++ b/git.c
@@ -89,8 +89,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 		 * Check remaining flags.
 		 */
 		if (skip_prefix(cmd, "--exec-path", &cmd)) {
-			if (*cmd == '=')
+			if (*cmd == '=') {
 				git_set_argv_exec_path(cmd + 1);
+				if (envchanged)
+					*envchanged = 1;
+			}
 			else {
 				puts(git_exec_path());
 				exit(0);
@@ -106,6 +109,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			exit(0);
 		} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
 			use_pager = 1;
+			if (envchanged)
+				*envchanged = 1;
 		} else if (!strcmp(cmd, "--no-pager")) {
 			use_pager = 0;
 			if (envchanged)
@@ -171,6 +176,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 				usage(git_usage_string);
 			}
 			git_config_push_parameter((*argv)[1]);
+			if (envchanged)
+				*envchanged = 1;
 			(*argv)++;
 			(*argc)--;
 		} else if (!strcmp(cmd, "--literal-pathspecs")) {
-- 
2.2.1.531.g5addc96.dirty
Alexander Kuleshov· Jan 10, 2015, 18:07 UTC · re: Alexander Kuleshov · lore

Re: [PATCH] git.c: prevent change of environment variables

There is aliasing of git -c .... in t1300-repo-config.sh, but I see:
die("alias '%s' changes environment variables\n"
      "You can use '!git' in the alias to do this.",
      alias_command);
at git.c, how to be here?
Thank you.
2015-01-10 18:53 GMT+06:00 Alexander Kuleshov <kuleshovmail@gmail.com>:
Show 54 quoted lines
> We can't change environment variables in aliases which doesn't start with '!'
>
> * 'git --exec-path=path' changes $GIT_EXEC_PATH variable in
> git_set_argv_exec_path
>
> * 'git -p/--paginate' sets 'use_pager' to 1 and commit_pager_choice
> will change $GIT_PAGER_IN_USE variable in setup_pager(void) from pager.c
>
> * 'git -c' calls git_config_push_parameter which will change
> $GIT_CONFIG_PARAMETERS variable
>
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
>  git.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/git.c b/git.c
> index c9bec99..3e87f05 100644
> --- a/git.c
> +++ b/git.c
> @@ -89,8 +89,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
>                  * Check remaining flags.
>                  */
>                 if (skip_prefix(cmd, "--exec-path", &cmd)) {
> -                       if (*cmd == '=')
> +                       if (*cmd == '=') {
>                                 git_set_argv_exec_path(cmd + 1);
> +                               if (envchanged)
> +                                       *envchanged = 1;
> +                       }
>                         else {
>                                 puts(git_exec_path());
>                                 exit(0);
> @@ -106,6 +109,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
>                         exit(0);
>                 } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
>                         use_pager = 1;
> +                       if (envchanged)
> +                               *envchanged = 1;
>                 } else if (!strcmp(cmd, "--no-pager")) {
>                         use_pager = 0;
>                         if (envchanged)
> @@ -171,6 +176,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
>                                 usage(git_usage_string);
>                         }
>                         git_config_push_parameter((*argv)[1]);
> +                       if (envchanged)
> +                               *envchanged = 1;
>                         (*argv)++;
>                         (*argc)--;
>                 } else if (!strcmp(cmd, "--literal-pathspecs")) {
> --
> 2.2.1.531.g5addc96.dirty
>
-- 
_________________________
0xAX

← back to recent threads