From: Frans Klaver <fransklaver@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Frans Klaver <fransklaver@gmail.com>
Subject: [PATCH] run-command.c: Accept EACCES as command not found
Date: Mon, 21 Nov 2011 22:53:07 +0100 [thread overview]
Message-ID: <1321912387-4569-1-git-send-email-fransklaver@gmail.com> (raw)
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
next reply other threads:[~2011-11-21 21:54 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-21 21:53 Frans Klaver [this message]
2011-11-21 22:13 ` [PATCH] run-command.c: Accept EACCES as command not found 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1321912387-4569-1-git-send-email-fransklaver@gmail.com \
--to=fransklaver@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).