sockets: improve error reporting if UNIX socket path is too long
commitad9579aaa16d5b385922d49edac2c96c79bcfb62
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 25 May 2017 15:53:00 +0000 (25 16:53 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 7 Jun 2017 16:22:02 +0000 (7 18:22 +0200)
treee5c01384ad220119c515d074354991ea96304722
parent5b003a40bb1ab14d0398e91f03393d3c6b9577cd
sockets: improve error reporting if UNIX socket path is too long

The 'struct sockaddr_un' only allows 108 bytes for the socket
path.

If the user supplies a path, QEMU uses snprintf() to silently
truncate it when too long. This is undesirable because the user
will then be unable to connect to the path they asked for.

If the user doesn't supply a path, QEMU builds one based on
TMPDIR, but if that leads to an overlong path, it mistakenly
uses error_setg_errno() with a stale errno value, because
snprintf() does not set errno on truncation.

In solving this the code needed some refactoring to ensure we
don't pass 'un.sun_path' directly to any APIs which expect
NUL-terminated strings, because the path is not required to
be terminated.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <20170525155300.22743-1-berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/qemu-sockets.c