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>
Alex Riesen committed
Dec 1, 2005 at 13:48 UTC
10b15b86f545e081aebba8783ad9e9acf6bf0d98
1 file changed
+12
-7
git.c
+12
-7
@@ -283,16 +283,21 @@ int main(int argc, char **argv, char **envp)
283
len = strlen(git_command);
284
prepend_to_path(git_command, len);
285
286
- strncat(&git_command[len], "/git-", sizeof(git_command) - len);
287
- len += 5;
288
- strncat(&git_command[len], argv[i], sizeof(git_command) - len);
289
-
290
- if (access(git_command, X_OK))
291
- usage(exec_path, "'%s' is not a git-command", argv[i]);
286
+ len += snprintf(git_command + len, sizeof(git_command) - len,
287
+ "/git-%s", argv[i]);
288
+ if (sizeof(git_command) <= len) {
289
+ fprintf(stderr, "git: command name given is too long (%d)\n", len);
290
+ exit(1);
291
+ }
292
293
/* execve() can only ever return if it fails */
294
execve(git_command, &argv[i], envp);
295
- printf("Failed to run command '%s': %s\n", git_command, strerror(errno));
295
+
296
+ if (errno == ENOENT)
297
+ usage(exec_path, "'%s' is not a git-command", argv[i]);
298
+
299
+ fprintf(stderr, "Failed to run command '%s': %s\n",
300
+ git_command, strerror(errno));
301
302
return 1;
303
}