connect.c: handle errors from split_cmdline
Commit e9d9a8a4d (connect: handle putty/plink also in GIT_SSH_COMMAND, 2017-01-02) added a call to split_cmdline(), but checks only for a non-zero return to see if we got any output. Since the function returns negative values (and a NULL argv) on error, we end up dereferencing NULL and segfaulting. Arguably we could report on the parsing error here, but it's probably not worth it. This is a best-effort attempt to see if we are using plink. So we can simply return here with "no, it wasn't plink" and let the shell actually complain about the bogus quoting. Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Apr 10, 2017 at 20:30 UTC
22e5ae5c8e6859e5670a2c6bbf5798778373144c
2 files changed
+7
-1
connect.c
+1
-1
@@ -730,7 +730,7 @@ static void handle_ssh_variant(const char *ssh_command, int is_cmdline,
730
const char **ssh_argv;
731
732
p = xstrdup(ssh_command);
733
- if (split_cmdline(p, &ssh_argv)) {
733
+ if (split_cmdline(p, &ssh_argv) > 0) {
734
variant = basename((char *)ssh_argv[0]);
735
/*
736
* At this point, variant points into the buffer
t/t5601-clone.sh
+6
@@ -427,6 +427,12 @@ test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' '
427
expect_ssh "-batch -P 123" myhost src
428
'
429
430
+test_expect_success 'clean failure on broken quoting' '
431
+ test_must_fail \
432
+ env GIT_SSH_COMMAND="${SQ}plink.exe -v" \
433
+ git clone "[myhost:123]:src" sq-failure
434
+'
435
+
436
# Reset the GIT_SSH environment variable for clone tests.
437
setup_ssh_wrapper
438