Skip to content

Commit

Permalink
vnc: avoid underflow when accessing user-provided address
Browse files Browse the repository at this point in the history
If hostlen is zero, there is a possibility that addrstr[hostlen - 1]
underflows and, if a closing bracked is there, hostlen - 2 is passed
to g_strndup() on the next line.  If websocket==false then
addrstr[0] would be a colon, but if websocket==true this could in
principle happen.

Fix it by checking hostlen.

Reported by Coverity.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 3f9c41c)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
bonzini authored and Michael Tokarev committed Apr 27, 2023
1 parent 161e1f2 commit bfc5327
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ui/vnc.c
Expand Up @@ -3765,7 +3765,7 @@ static int vnc_display_get_address(const char *addrstr,

addr->type = SOCKET_ADDRESS_TYPE_INET;
inet = &addr->u.inet;
if (addrstr[0] == '[' && addrstr[hostlen - 1] == ']') {
if (hostlen && addrstr[0] == '[' && addrstr[hostlen - 1] == ']') {
inet->host = g_strndup(addrstr + 1, hostlen - 2);
} else {
inet->host = g_strndup(addrstr, hostlen);
Expand Down

0 comments on commit bfc5327

Please sign in to comment.