librdmacm: reject negative indexes in idm_lookup Negative fd values were not rejected and could index before the idm array. Fold the fd >= 0 check into idm_lookup so callers need not duplicate it. Signed-off-by: Batsheva Black <bblack@nvidia.com>
diff --git a/librdmacm/indexer.h b/librdmacm/indexer.h index e6ffc60..c37ea21 100644 --- a/librdmacm/indexer.h +++ b/librdmacm/indexer.h
@@ -97,7 +97,8 @@ static inline void *idm_lookup(struct index_map *idm, int index) { - return ((index <= IDX_MAX_INDEX) && idm->array[idx_array_index(index)]) ? + return ((index >= 0) && (index <= IDX_MAX_INDEX) && + idm->array[idx_array_index(index)]) ? idm_at(idm, index) : NULL; }