summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2009-01-08 17:06:19 -0800
committerBen Pfaff <blp@nicira.com>2009-01-12 17:17:30 -0800
commitf93f95f58257e684f84d97644f98b8044eb7bede (patch)
tree5ec3423e6544447f9519765177d5e7fda64748e1
parent82f2a1fbd5f1730ee44ed5cc86f56126b6c15186 (diff)
downloadopenvswitch-f93f95f58257e684f84d97644f98b8044eb7bede.tar.gz
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.
-rw-r--r--datapath/datapath.c7
-rw-r--r--datapath/dp_dev.c3
2 files changed, 8 insertions, 2 deletions
diff --git a/datapath/datapath.c b/datapath/datapath.c
index 338147f78..b1bcee874 100644
--- a/datapath/datapath.c
+++ b/datapath/datapath.c
@@ -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;
diff --git a/datapath/dp_dev.c b/datapath/dp_dev.c
index 7a726c39a..ec36361d6 100644
--- a/datapath/dp_dev.c
+++ b/datapath/dp_dev.c
@@ -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];