Miscellaneous patches for 2017-03-28
The following changes since commit 4d2bee82f4276b6f694fa2b0b179b4b3673984f6:
Merge remote-tracking branch 'remotes/armbru/tags/pull-block-2017-03-28' into staging (2017-03-28 14:48:07 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/armbru.git tags/pull-misc-2017-03-28
for you to fetch changes up to 44fdc764550e048a2810955da7cabbfaf636231a:
sockets: Fix socket_address_to_string() hostname truncation (2017-03-28 18:50:38 +0200)
----------------------------------------------------------------
Miscellaneous patches for 2017-03-28
----------------------------------------------------------------
Markus Armbruster (1):
sockets: Fix socket_address_to_string() hostname truncation
util/qemu-sockets.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
Markus Armbruster (1):
sockets: Fix socket_address_to_string() hostname truncation
util/qemu-sockets.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
[Qemu-devel] [PULL for-2.9] sockets: Fix socket_address_to_string() hostname truncation
We first snprintf() to a fixed buffer, then g_strdup() the result *boggle*.
Worse, the size of the fixed buffer INET6_ADDRSTRLEN + 5 + 4 is bogus:
the 4 correctly accounts for '[', ']', ':' and '\0', but INET6_ADDRSTRLEN is not a suitable limit for inet->host, and 5 is not one for inet->port! They are for host and port in *numeric* form (exploiting that INET6_ADDRSTRLEN > INET_ADDRSTRLEN), but inet->host can also be a hostname, and inet->port can be a service name, to be resolved with getaddrinfo().
Fortunately, the only user so far is the "socket" network backend's net_socket_connected(), which uses it to initialize a NetSocketState's info_str[]. info_str[] has considerable more space: 256 instead of
55. So the bug's impact appears to be limited to truncated "info networks" with the "socket" network backend.
The fix is obvious: use g_strdup_printf().
Message-Id: <[email protected]>
--- util/qemu-sockets.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
util/qemu-sockets.c +2 -7
@@ -1307,19 +1307,14 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp) {char *buf;InetSocketAddress *inet; -char host_port[INET6_ADDRSTRLEN +5 +4 ];switch (addr->type) {case SOCKET_ADDRESS_KIND_INET : inet = addr->u.inet.data;if (strchr (inet->host,':' ) ==NULL ) { -snprintf (host_port,sizeof (host_port),"%s:%s" , inet->host, - inet->port); - buf =g_strdup (host_port); + buf =g_strdup_printf ("%s:%s" , inet->host, inet->port); }else { -snprintf (host_port,sizeof (host_port),"[%s]:%s" , inet->host, - inet->port); - buf =g_strdup (host_port); + buf =g_strdup_printf ("[%s]:%s" , inet->host, inet->port); }break ;
Signature · 1 line
2.7.4
Peter Maydell
AppliedQuoted 19 lines · Markus Armbruster
The following changes since commit
4d2bee82f4276b6f694fa2b0b179b4b3673984f6:Merge remote-tracking branch 'remotes/armbru/tags/pull-block-2017-03-28' into staging (2017-03-28 14:48:07 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/armbru.gittags/pull-misc-2017-03-28for you to fetch changes up to
44fdc764550e048a2810955da7cabbfaf636231a:sockets: Fix
socket_address_to_string()hostname truncation (2017-03-28 18:50:38 +0200)----------------------------------------------------------------
Miscellaneous patches for 2017-03-28----------------------------------------------------------------
Markus Armbruster (1):
sockets: Fixsocket_address_to_string()hostname truncation
Quoted 8 lines
util/qemu-sockets.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)Markus Armbruster (1):
sockets: Fixsocket_address_to_string()hostname truncationutil/qemu-sockets.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
Applied, thanks.
-- PMM