@matheusbsbs / matheus-bagliano / commits / 95d3c4f546
Fork 0

Use /dev/null for update hook stdin.

Currently the update hook invoked by receive-pack has its stdin connected to the pushing client. The hook shouldn't attempt to read from this stream, and doing so may consume data that was meant for receive-pack. Instead we should give the update hook /dev/null as its stdin, ensuring that it always receives EOF and doesn't disrupt the protocol if it attempts to read any data. The post-update hook is similar, as it gets invoked with /dev/null on stdin to prevent the hook from reading data from the client. Previously we had invoked it with stdout also connected to /dev/null, throwing away anything on stdout, to prevent client protocol errors. Instead we should redirect stdout to stderr, like we do with the update hook. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Dec 30, 2006 at 21:55 UTC 95d3c4f546c664c3571dd4a93f11ae2f54e55e6e
3 files changed +8 -6
receive-pack.c
+4 -2
@@ -73,7 +73,8 @@ static int run_update_hook(const char *refname,
73
74 if (access(update_hook, X_OK) < 0)
75 return 0;
76 - code = run_command_opt(RUN_COMMAND_STDOUT_TO_STDERR,
76 + code = run_command_opt(RUN_COMMAND_NO_STDIN
77 + | RUN_COMMAND_STDOUT_TO_STDERR,
78 update_hook, refname, old_hex, new_hex, NULL);
79 switch (code) {
80 case 0:
@@ -188,7 +189,8 @@ static void run_update_post_hook(struct command *cmd)
189 argc++;
190 }
191 argv[argc] = NULL;
191 - run_command_v_opt(argv, RUN_COMMAND_NO_STDIO);
192 + run_command_v_opt(argv, RUN_COMMAND_NO_STDIN
193 + | RUN_COMMAND_STDOUT_TO_STDERR);
194 }
195
196 /*
run-command.c
+3 -3
@@ -9,12 +9,12 @@ int run_command_v_opt(const char **argv, int flags)
9 if (pid < 0)
10 return -ERR_RUN_COMMAND_FORK;
11 if (!pid) {
12 - if (flags & RUN_COMMAND_NO_STDIO) {
12 + if (flags & RUN_COMMAND_NO_STDIN) {
13 int fd = open("/dev/null", O_RDWR);
14 dup2(fd, 0);
15 - dup2(fd, 1);
15 close(fd);
17 - } else if (flags & RUN_COMMAND_STDOUT_TO_STDERR)
16 + }
17 + if (flags & RUN_COMMAND_STDOUT_TO_STDERR)
18 dup2(2, 1);
19 if (flags & RUN_GIT_CMD) {
20 execv_git_cmd(argv);
run-command.h
+1 -1
@@ -11,7 +11,7 @@ enum {
11 ERR_RUN_COMMAND_WAITPID_NOEXIT,
12 };
13
14 -#define RUN_COMMAND_NO_STDIO 1
14 +#define RUN_COMMAND_NO_STDIN 1
15 #define RUN_GIT_CMD 2 /*If this is to be git sub-command */
16 #define RUN_COMMAND_STDOUT_TO_STDERR 4
17 int run_command_v_opt(const char **argv, int opt);