git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] run-command.c: Accept EACCES as command not found
@ 2011-11-21 21:53 Frans Klaver
  2011-11-21 22:13 ` Junio C Hamano
  0 siblings, 1 reply; 25+ messages in thread
From: Frans Klaver @ 2011-11-21 21:53 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Frans Klaver

execvp returns ENOENT if a command was not found after searching PATH.
If path contains a directory that current user has insufficient
privileges to, EACCES is returned. This may still mean the program
wasn't found.

If the latter case is encountered, git errors out without giving aliases
a try, which breaks t0001.3 and alias handling in general.

This can be fixed by handling the EACCES case equally to the ENOENT
case.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
---

I'm actually not too happy about the location of the tests. I couldn't
find out from the available tests and the documentation where I would
have to create the new ones. For now, I've added the tests to the same
set that I found the issue with.

 run-command.c   |   10 ++++++++--
 t/t0001-init.sh |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/run-command.c b/run-command.c
index 1c51043..ad3c120 100644
--- a/run-command.c
+++ b/run-command.c
@@ -280,12 +280,18 @@ fail_pipe:
 		} else {
 			execvp(cmd->argv[0], (char *const*) cmd->argv);
 		}
-		if (errno == ENOENT) {
+		switch (errno) {
+		case ENOENT:
 			if (!cmd->silent_exec_failure)
 				error("cannot run %s: %s", cmd->argv[0],
 					strerror(ENOENT));
 			exit(127);
-		} else {
+		case EACCES:
+			if (!cmd->silent_exec_failure)
+				error("fatal: cannot exec '%s': %s", cmd->argv[0],
+					strerror(EACCES));
+			exit(127);
+		default:
 			die_errno("cannot exec '%s'", cmd->argv[0]);
 		}
 	}
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index ad66410..d40966a 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -63,6 +63,54 @@ test_expect_success 'plain through aliased command, outside any git repo' '
 	check_config plain-aliased/.git false unset
 '
 
+test_expect_success 'plain through aliased command, inaccessible path, outside any git repo' '
+	(
+		sane_unset GIT_DIR GIT_WORK_TREE &&
+		HOME=$(pwd)/alias-config-path &&
+		export HOME &&
+		mkdir alias-config-path &&
+		echo "[alias] aliasedinit = init" >alias-config-path/.gitconfig &&
+
+		GIT_CEILING_DIRECTORIES=$(pwd) &&
+		export GIT_CEILING_DIRECTORIES &&
+
+		mkdir searchpath &&
+		chmod 400 searchpath &&
+		PATH=$(pwd)/searchpath:$PATH &&
+		export PATH &&
+
+		mkdir plain-aliased-path &&
+		cd plain-aliased-path &&
+		git aliasedinit
+	) &&
+	check_config plain-aliased-path/.git false unset
+'
+
+test_expect_success 'plain through aliased command, inaccessible command, outside any git repo' '
+	(
+		sane_unset GIT_DIR GIT_WORK_TREE &&
+		HOME=$(pwd)/alias-config-cmd &&
+		export HOME &&
+		mkdir alias-config-cmd &&
+		echo "[alias] aliasedinit = init" >alias-config-cmd/.gitconfig &&
+
+		GIT_CEILING_DIRECTORIES=$(pwd) &&
+		export GIT_CEILING_DIRECTORIES &&
+
+		mkdir searchpathcmd &&
+		chmod 755 searchpathcmd &&
+		PATH=$(pwd)/searchpathcmd:$PATH &&
+		export PATH &&
+
+		touch searchpathcmd/git-aliasedinit &&
+
+		mkdir plain-aliased-cmd &&
+		cd plain-aliased-cmd &&
+		git aliasedinit
+	) &&
+	check_config plain-aliased-cmd/.git false unset
+'
+
 test_expect_failure 'plain nested through aliased command' '
 	(
 		sane_unset GIT_DIR GIT_WORK_TREE &&
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2011-12-14 22:06 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-21 21:53 [PATCH] run-command.c: Accept EACCES as command not found Frans Klaver
2011-11-21 22:13 ` Junio C Hamano
2011-11-21 23:06   ` Frans Klaver
2011-11-21 23:54     ` Junio C Hamano
2011-11-22  9:31       ` Frans Klaver
2011-11-23  8:17         ` Frans Klaver
2011-11-23 12:04           ` Nguyen Thai Ngoc Duy
2011-11-23 13:25             ` Frans Klaver
2011-11-23 22:55           ` Frans Klaver
2011-12-06 21:38             ` [PATCH 0/2] run-command: Add EACCES diagnostics Frans Klaver
2011-12-06 21:38               ` [PATCH 1/2] run-command: Add checks after execvp fails with EACCES Frans Klaver
2011-12-06 22:35                 ` Junio C Hamano
2011-12-07  8:31                   ` Frans Klaver
2011-12-08 21:44                   ` Frans Klaver
2011-12-09 17:23                     ` Junio C Hamano
2011-12-09 21:35                       ` Frans Klaver
2011-12-06 21:38               ` [PATCH 2/2] run-command: Add interpreter permissions check Frans Klaver
2011-12-06 22:47                 ` Junio C Hamano
2011-12-07  8:37                   ` Frans Klaver
2011-12-13 15:08             ` [PATCH 0/2 v2] run-command: Add eacces diagnostics Frans Klaver
2011-12-13 15:08               ` [PATCH 1/2] run-command: Add checks after execvp fails with EACCES Frans Klaver
2011-12-13 19:01                 ` Junio C Hamano
2011-12-14 14:31                   ` Frans Klaver
2011-12-14 22:06                     ` Frans Klaver
2011-12-13 15:08               ` [PATCH 2/2] run-command: Add interpreter permissions check Frans Klaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).