diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/hook.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -135,7 +135,11 @@ static int object_id_ok(const char *s) static char *head_ref(hook_opts o, int *unknown) { - const char *argv[4]; + /* Terminated by hand, and by name: execvp walks this array until it finds + * the NULL, and an array that runs off the end takes whatever is on the + * stack next as an argument - which is not a crash you can read, and made + * every deletion cost admin because the answer was never received. */ + const char *argv[5] = { "git", "symbolic-ref", "-q", "HEAD", NULL }; char *out = NULL; int rc; @@ -147,10 +151,6 @@ static char *head_ref(hook_opts o, int *unknown) if (!o.use_git) return NULL; /* told not to ask, so do not guess either way */ - argv[0] = "git"; - argv[1] = "symbolic-ref"; - argv[2] = "-q"; - argv[3] = "HEAD"; rc = spawn(argv, 1, &out); if (rc == 0 && out != NULL && out[0] != '\0') return out; @@ -162,7 +162,9 @@ static char *head_ref(hook_opts o, int *unknown) /* Is old an ancestor of new? */ static int fast_forward(hook_opts o, const char *old, const char *new) { - const char *argv[5]; + /* Same as head_ref: the NULL is part of the contract, not padding. */ + const char *argv[6] = { "git", "merge-base", "--is-ancestor", + NULL, NULL, NULL }; int rc; if (strcmp(o.ff, "yes") == 0) @@ -172,9 +174,6 @@ static int fast_forward(hook_opts o, const char *old, const char *new) if (!o.use_git) return 0; - argv[0] = "git"; - argv[1] = "merge-base"; - argv[2] = "--is-ancestor"; argv[3] = old; argv[4] = new; rc = spawn(argv, 0, NULL); |
