diff options
author | Bill Fischofer <bill.fischofer@linaro.org> | 2017-02-02 18:28:02 -0600 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2017-02-10 00:13:16 +0300 |
commit | 0ed479bd9d474f1d7588f3370fb306a2e000ff4f (patch) | |
tree | af8f3b34bd4844dcaf2fa096b1dea4705c8147cd | |
parent | 483af96a7a14885694496843551ed8fad708192c (diff) |
helper: tables: avoid invalid odp_shm_addr() calls
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.fischofer@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r-- | helper/cuckootable.c | 7 | ||||
-rw-r--r-- | helper/hashtable.c | 7 | ||||
-rw-r--r-- | helper/iplookuptable.c | 5 | ||||
-rw-r--r-- | helper/lineartable.c | 7 |
4 files changed, 19 insertions, 7 deletions
diff --git a/helper/cuckootable.c b/helper/cuckootable.c index 6a7fb215e..80ff49893 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 1c2b85234..9d4114445 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 9abdab229..aae219945 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 e1a396c19..32c4956ee 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 && |