datapath: Avoid pointer arithmetic on possibly-NULL pointer.
authorBen Pfaff <blp@nicira.com>
Fri, 9 Jan 2009 01:06:19 +0000 (17:06 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 13 Jan 2009 01:17:30 +0000 (17:17 -0800)
Pointer arithmetic on a null pointer yields undefined behavior, even
though it doesn't really matter in the real world (normally).

Found by Chris Eagle via Fortify.

datapath/datapath.c
datapath/dp_dev.c

index 338147f..b1bcee8 100644 (file)
@@ -1826,7 +1826,11 @@ static void dp_uninit_netlink(void)
 static void set_desc(void)
 {
        const char *uuid = dmi_get_system_info(DMI_PRODUCT_UUID);
-       const char *uptr = uuid + 24;
+       const char *vendor = dmi_get_system_info(DMI_SYS_VENDOR);
+       const char *name = dmi_get_system_info(DMI_PRODUCT_NAME);
+       const char *version = dmi_get_system_info(DMI_PRODUCT_VERSION);
+       const char *serial = dmi_get_system_info(DMI_PRODUCT_SERIAL);
+       const char *uptr;
 
        if (!uuid || *uuid == '\0' || strlen(uuid) != 36) 
                return;
@@ -1837,6 +1841,7 @@ static void set_desc(void)
                return;
 
        /* Only set if the UUID is from Nicira. */
+       uptr = uuid + 24;
        if (strncmp(uptr, NICIRA_OUI_STR, strlen(NICIRA_OUI_STR)))
                return;
 
index 7a726c3..ec36361 100644 (file)
@@ -129,7 +129,7 @@ static void
 set_uuid_mac(struct net_device *netdev)
 {
        const char *uuid = dmi_get_system_info(DMI_PRODUCT_UUID);
-       const char *uptr = uuid + 24;
+       const char *uptr;
        uint8_t mac[ETH_ALEN];
        int i;
 
@@ -143,6 +143,7 @@ set_uuid_mac(struct net_device *netdev)
 
        /* Pull out the embedded MAC address.  The kernel's sscanf doesn't
         * support field widths on hex digits, so we use this hack. */
+       uptr = uuid + 24;
        for (i=0; i<ETH_ALEN; i++) {
                unsigned char d[3];