In the various table lookup routines, check that odp_shm_lookup() returns
a valid handle before attempting to dereference it via odp_shm_addr().

Signed-off-by: Bill Fischofer <bill.fischo...@linaro.org>
---
 helper/cuckootable.c   | 7 +++++--
 helper/hashtable.c     | 7 +++++--
 helper/iplookuptable.c | 5 ++++-
 helper/lineartable.c   | 7 +++++--
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/helper/cuckootable.c b/helper/cuckootable.c
index 6a7fb215..80ff4989 100644
--- a/helper/cuckootable.c
+++ b/helper/cuckootable.c
@@ -151,12 +151,15 @@ align32pow2(uint32_t x)
 odph_table_t
 odph_cuckoo_table_lookup(const char *name)
 {
-       odph_cuckoo_table_impl *tbl;
+       odph_cuckoo_table_impl *tbl = NULL;
+       odp_shm_t shm;
 
        if (name == NULL || strlen(name) >= ODPH_TABLE_NAME_LEN)
                return NULL;
 
-       tbl = (odph_cuckoo_table_impl *)odp_shm_addr(odp_shm_lookup(name));
+       shm = odp_shm_lookup(name);
+       if (shm != ODP_SHM_INVALID)
+               tbl = (odph_cuckoo_table_impl *)odp_shm_addr(shm);
        if (!tbl || tbl->magicword != ODPH_CUCKOO_TABLE_MAGIC_WORD)
                return NULL;
 
diff --git a/helper/hashtable.c b/helper/hashtable.c
index 1c2b8523..9d411444 100644
--- a/helper/hashtable.c
+++ b/helper/hashtable.c
@@ -150,12 +150,15 @@ int odph_hash_table_destroy(odph_table_t table)
 
 odph_table_t odph_hash_table_lookup(const char *name)
 {
-       odph_hash_table_imp *hash_tbl;
+       odph_hash_table_imp *hash_tbl = NULL;
+       odp_shm_t shm;
 
        if (name == NULL || strlen(name) >= ODPH_TABLE_NAME_LEN)
                return NULL;
 
-       hash_tbl = (odph_hash_table_imp *)odp_shm_addr(odp_shm_lookup(name));
+       shm = odp_shm_lookup(name);
+       if (shm != ODP_SHM_INVALID)
+               hash_tbl = (odph_hash_table_imp *)odp_shm_addr(shm);
        if (hash_tbl != NULL && strcmp(hash_tbl->name, name) == 0)
                return (odph_table_t)hash_tbl;
        return NULL;
diff --git a/helper/iplookuptable.c b/helper/iplookuptable.c
index 9abdab22..aae21994 100644
--- a/helper/iplookuptable.c
+++ b/helper/iplookuptable.c
@@ -419,11 +419,14 @@ odph_table_t
 odph_iplookup_table_lookup(const char *name)
 {
        odph_iplookup_table_impl *tbl = NULL;
+       odp_shm_t shm;
 
        if (name == NULL || strlen(name) >= ODPH_TABLE_NAME_LEN)
                return NULL;
 
-       tbl = (odph_iplookup_table_impl *)odp_shm_addr(odp_shm_lookup(name));
+       shm = odp_shm_lookup(name);
+       if (shm != ODP_SHM_INVALID)
+               tbl = (odph_iplookup_table_impl *)odp_shm_addr(shm);
 
        if (
                tbl != NULL &&
diff --git a/helper/lineartable.c b/helper/lineartable.c
index e1a396c1..32c4956e 100644
--- a/helper/lineartable.c
+++ b/helper/lineartable.c
@@ -128,12 +128,15 @@ int odph_linear_table_destroy(odph_table_t table)
 
 odph_table_t odph_linear_table_lookup(const char *name)
 {
-       odph_linear_table_imp *tbl;
+       odph_linear_table_imp *tbl = NULL;
+       odp_shm_t shm;
 
        if (name == NULL || strlen(name) >= ODPH_TABLE_NAME_LEN)
                return NULL;
 
-       tbl = (odph_linear_table_imp *)odp_shm_addr(odp_shm_lookup(name));
+       shm = odp_shm_lookup(name);
+       if (shm != ODP_SHM_INVALID)
+               tbl = (odph_linear_table_imp *)odp_shm_addr(shm);
 
        /* check magicword to make sure the memory block is used by a table */
        if (tbl != NULL &&
-- 
2.11.0.295.gd7dffce

Reply via email to