]> git.proxmox.com Git - mirror_qemu.git/commitdiff
net: Zero sockaddr_in in parse_host_port()
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 13 Aug 2021 15:05:03 +0000 (16:05 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 26 Aug 2021 16:02:00 +0000 (17:02 +0100)
We don't currently zero-initialize the 'struct sockaddr_in' that
parse_host_port() fills in, so any fields we don't explicitly
initialize might be left as random garbage.  POSIX states that
implementations may define extensions in sockaddr_in, and that those
extensions must not trigger if zero-initialized.  So not zero
initializing might result in inadvertently triggering an impdef
extension.

memset() the sockaddr_in before we start to fill it in.

Fixes: Coverity CID 1005338
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20210813150506.7768-2-peter.maydell@linaro.org

net/net.c

index 76bbb7c31b49f0cf141279b89d035f801a255194..52c99196c69660277f49418370b29b74d39ef024 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -75,6 +75,8 @@ int parse_host_port(struct sockaddr_in *saddr, const char *str,
     const char *addr, *p, *r;
     int port, ret = 0;
 
+    memset(saddr, 0, sizeof(*saddr));
+
     substrings = g_strsplit(str, ":", 2);
     if (!substrings || !substrings[0] || !substrings[1]) {
         error_setg(errp, "host address '%s' doesn't contain ':' "