git wrapper: more careful argument stuffing
- Use stderr for error output - Build git_command more careful - ENOENT is good enough for check of failed exec to show usage, no access() check needed [jc: Originally from Alex Riesen with inputs from Sven Verdoolaege mixed in.] Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
ce3ca27545
commit
10b15b86f5
19
git.c
19
git.c
@ -283,16 +283,21 @@ int main(int argc, char **argv, char **envp)
|
|||||||
len = strlen(git_command);
|
len = strlen(git_command);
|
||||||
prepend_to_path(git_command, len);
|
prepend_to_path(git_command, len);
|
||||||
|
|
||||||
strncat(&git_command[len], "/git-", sizeof(git_command) - len);
|
len += snprintf(git_command + len, sizeof(git_command) - len,
|
||||||
len += 5;
|
"/git-%s", argv[i]);
|
||||||
strncat(&git_command[len], argv[i], sizeof(git_command) - len);
|
if (sizeof(git_command) <= len) {
|
||||||
|
fprintf(stderr, "git: command name given is too long (%d)\n", len);
|
||||||
if (access(git_command, X_OK))
|
exit(1);
|
||||||
usage(exec_path, "'%s' is not a git-command", argv[i]);
|
}
|
||||||
|
|
||||||
/* execve() can only ever return if it fails */
|
/* execve() can only ever return if it fails */
|
||||||
execve(git_command, &argv[i], envp);
|
execve(git_command, &argv[i], envp);
|
||||||
printf("Failed to run command '%s': %s\n", git_command, strerror(errno));
|
|
||||||
|
if (errno == ENOENT)
|
||||||
|
usage(exec_path, "'%s' is not a git-command", argv[i]);
|
||||||
|
|
||||||
|
fprintf(stderr, "Failed to run command '%s': %s\n",
|
||||||
|
git_command, strerror(errno));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user