From: Ben Pfaff Date: Fri, 9 Jan 2009 01:06:19 +0000 (-0800) Subject: datapath: Avoid pointer arithmetic on possibly-NULL pointer. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c878f1fe3108ab0c97048a8ddc47db10b3d4407;p=openvswitch datapath: Avoid pointer arithmetic on possibly-NULL pointer. 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. --- diff --git a/datapath/datapath.c b/datapath/datapath.c index 1043742e..7f69d478 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -1927,7 +1927,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; @@ -1938,6 +1942,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; diff --git a/datapath/dp_dev.c b/datapath/dp_dev.c index cec7fbfa..2c99d602 100644 --- a/datapath/dp_dev.c +++ b/datapath/dp_dev.c @@ -130,7 +130,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; @@ -144,6 +144,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