]> xenbits.xensource.com Git - mini-os.git/commitdiff
mini-os: netfront: fix initialization without ip address in xenstore
authorJuergen Gross <jgross@suse.com>
Thu, 19 Aug 2021 05:30:56 +0000 (07:30 +0200)
committerWei Liu <wl@xen.org>
Tue, 31 Aug 2021 15:57:40 +0000 (15:57 +0000)
Commit 4821876fcd2ff ("mini-os: netfront: fix suspend/resume handling")
introduced a NULL pointer dereference in the initialization of netfront
in the case of no IP address being set in Xenstore.

Fix that by testing this condition. At the same time fix a long
standing bug for the same condition if someone used init_netfront()
with a non-NULL ip parameter.

Fixes: 4821876fcd2ff ("mini-os: netfront: fix suspend/resume handling")
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
netfront.c

index f927e99cd501009ab84d6b08dcd57645f1e48f5f..dfe065be182f2a030576386043be3b89782eb0cf 100644 (file)
@@ -365,7 +365,7 @@ out:
         rawmac[5] = dev->rawmac[5];
        }
     if (ip)
-        *ip = strdup(dev->ip);
+        *ip = dev->ip ? strdup(dev->ip) : NULL;
 
 err:
     return dev;
@@ -527,7 +527,7 @@ done:
         snprintf(path, sizeof(path), "%s/ip", dev->backend);
         xenbus_read(XBT_NIL, path, &dev->ip);
 
-        p = strchr(dev->ip, ' ');
+        p = dev->ip ? strchr(dev->ip, ' ') : NULL;
         if (p) {
             *p++ = '\0';
             dev->mask = p;