diff options
author | Maxim Uvarov <maxim.uvarov@linaro.org> | 2015-02-27 15:21:55 +0300 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2015-03-27 18:06:04 +0300 |
commit | f8b6b705dd90b9409e5a00f613b79ba035c7aeb9 (patch) | |
tree | 72e5694f0befa6a1fbb1764caa85faf39727a013 /platform/linux-generic | |
parent | 70056994efc9a85d01540c1da143b72fb636eb50 (diff) |
linux-generic: pktio check for NULL entry
CID: 85427
https://bugs.linaro.org/show_bug.cgi?id=1175
get_pktio_entry() can return NULL entry then it can be derefenced
inside is_free(entry).
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>
Diffstat (limited to 'platform/linux-generic')
-rw-r--r-- | platform/linux-generic/include/odp_packet_io_internal.h | 10 | ||||
-rw-r--r-- | platform/linux-generic/odp_packet_io.c | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 47b899267..25d49fb1f 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -22,6 +22,7 @@ extern "C" { #include <odp_packet_socket.h> #include <odp_classification_datamodel.h> #include <odp_align_internal.h> +#include <odp_debug_internal.h> #include <odp/config.h> #include <odp/hints.h> @@ -67,10 +68,15 @@ extern void *pktio_entry_ptr[]; static inline pktio_entry_t *get_pktio_entry(odp_pktio_t id) { - if (odp_unlikely(id == ODP_PKTIO_INVALID || - _odp_typeval(id) > ODP_CONFIG_PKTIO_ENTRIES)) + if (odp_unlikely(id == ODP_PKTIO_INVALID)) return NULL; + if (odp_unlikely(_odp_typeval(id) > ODP_CONFIG_PKTIO_ENTRIES)) { + ODP_DBG("pktio limit %d/%d exceed\n", + _odp_typeval(id), ODP_CONFIG_PKTIO_ENTRIES); + return NULL; + } + return pktio_entry_ptr[_odp_typeval(id) - 1]; } #ifdef __cplusplus diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 21f0c17be..b04ce8bd9 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -339,7 +339,7 @@ odp_pktio_t odp_pktio_lookup(const char *dev) for (i = 1; i <= ODP_CONFIG_PKTIO_ENTRIES; ++i) { entry = get_pktio_entry(_odp_cast_scalar(odp_pktio_t, i)); - if (is_free(entry)) + if (!entry || is_free(entry)) continue; lock_entry(entry); |