libvirt/src/rpc
Daniel P. Berrangé 76d31244c5 rpc: fix escaping of shell path for netcat binary
Consider having a nc binary in the path with a space in its name,
for example '/tmp/fo o/nc'

This results in libvirt running SSH with the following arg value

  "'if ''/tmp/fo o/nc'' -q 2>&1 | grep \"requires
    an argument\" >/dev/null 2>&1; then ARG=-q0;
    else ARG=;fi;''/tmp/fo o/nc'' $ARG -U
    /var/run/libvirt/libvirt-sock'"

The use of the single quote escaping was introduced by

  commit 6ac6238de3
  Author: Guido Günther <agx@sigxcpu.org>
  Date:   Thu Oct 13 21:49:01 2011 +0200

    Use virBufferEscapeShell in virNetSocketNewConnectSSH

    to escape the netcat command since it's passed to the shell. Adjust
    expected test case output accordingly.

While the intention of this change was good, the result is broken as it
is still underquoted.

On the SSH server side, SSH itself runs the command via the shell.
Our command is then invoking the shell again. Thus we see

$ virsh -c qemu+ssh://root@domokun/system?netcat=%2Ftmp%2Ffo%20o%2Fnc list
error: failed to connect to the hypervisor
error: End of file while reading data: sh: /tmp/fo: No such file or directory: Input/output error

With the second level of escaping added we can now successfully use a nc
binary with a space in the path.

The original test case added was misleading as it illustrated using a
binary path of 'nc -4' which is not a path, it is a command with a
separate argument, which is getting interpreted as a path.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-01 12:57:07 +01:00
..
gendispatch.pl remote: Check for limits when encoding typed params 2019-08-28 11:17:16 +02:00
genprotocol.pl rpc: reproducible genprotocol output 2018-10-12 14:44:43 +02:00
gensystemtap.pl Remove all Author(s): lines from source file headers 2018-12-13 16:08:38 +00:00
Makefile.inc.am rpc: add $(SASL_CFLAGS) to libvirt_net_rpc_server_la_CFLAGS 2019-06-21 15:41:34 +01:00
virkeepalive.c Require a semicolon for VIR_ONCE_GLOBAL_INIT calls 2019-02-03 17:46:29 -05:00
virkeepalive.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00
virkeepaliveprotocol.x
virnetclient.c rpc: fix escaping of shell path for netcat binary 2019-10-01 12:57:07 +01:00
virnetclient.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00
virnetclientprogram.c Require a semicolon for VIR_ONCE_GLOBAL_INIT calls 2019-02-03 17:46:29 -05:00
virnetclientprogram.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00
virnetclientstream.c rpc: client: stream: fix multi thread abort/finish 2019-02-08 17:16:00 +01:00
virnetclientstream.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00
virnetdaemon.c rpc: make virNetDaemonCallInhibit a no-op with no logind 2019-08-14 16:22:13 +02:00
virnetdaemon.h rpc: remove unused typedef for auto shutdown function callback 2019-07-12 16:55:40 +01:00
virnetlibsshsession.c util: get rid of virGetEnv{Allow,Block}SUID functions 2019-08-07 16:54:02 +01:00
virnetlibsshsession.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00
virnetmessage.c src: More cleanup of some system headers already contained in internal.h 2018-09-20 10:16:39 +02:00
virnetmessage.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00
virnetprotocol.x Remove all Author(s): lines from source file headers 2018-12-13 16:08:38 +00:00
virnetsaslcontext.c rpc: ensure thread safe initialization of SASL library 2019-07-08 12:59:49 +01:00
virnetsaslcontext.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00
virnetserver.c rpc: add API for checking whether an auth scheme is in use on a server 2019-07-12 16:55:40 +01:00
virnetserver.h rpc: add API for checking whether an auth scheme is in use on a server 2019-07-12 16:55:40 +01:00
virnetserverclient.c remote: pass identity across to newly opened daemons 2019-09-16 11:25:53 +01:00
virnetserverclient.h remote: pass identity across to newly opened daemons 2019-09-16 11:25:53 +01:00
virnetserverprogram.c Require a semicolon for VIR_ONCE_GLOBAL_INIT calls 2019-02-03 17:46:29 -05:00
virnetserverprogram.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00
virnetserverservice.c rpc: remove unused API for creating services from FDs 2019-07-12 16:55:40 +01:00
virnetserverservice.h rpc: remove unused API for creating services from FDs 2019-07-12 16:55:40 +01:00
virnetsocket.c rpc: fix escaping of shell path for netcat binary 2019-10-01 12:57:07 +01:00
virnetsocket.h rpc: avoid unlinking sockets passed in from systemd 2019-07-12 16:55:39 +01:00
virnetsshsession.c misc: Drop useless checks from *Dispose() functions 2019-05-23 13:59:06 +02:00
virnetsshsession.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00
virnettlscontext.c util: get rid of virGetEnv{Allow,Block}SUID functions 2019-08-07 16:54:02 +01:00
virnettlscontext.h src/rpc: use #pragma once in headers 2019-06-19 17:12:30 +02:00