mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 13:58:14 +00:00
shash, simap, smap: Add assertions to *_count
functions.
This commit adds assertions in the functions `shash_count`, `simap_count`, and `smap_count` to ensure that the corresponding input struct pointer is not NULL. This ensures that if the return values of `shash_sort`, `simap_sort`, or `smap_sort` are NULL, then the following for loops would not attempt to access the pointer, which might result in segmentation faults or undefined behavior. Reviewed-by: Simon Horman <simon.horman@corigine.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: James Raphael Tiovalen <jamestiotio@gmail.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
committed by
Ilya Maximets
parent
a5fdc45b84
commit
62f5aa42aa
@@ -17,6 +17,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include "openvswitch/shash.h"
|
#include "openvswitch/shash.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static struct shash_node *shash_find__(const struct shash *,
|
static struct shash_node *shash_find__(const struct shash *,
|
||||||
const char *name, size_t name_len,
|
const char *name, size_t name_len,
|
||||||
@@ -100,6 +101,7 @@ shash_is_empty(const struct shash *shash)
|
|||||||
size_t
|
size_t
|
||||||
shash_count(const struct shash *shash)
|
shash_count(const struct shash *shash)
|
||||||
{
|
{
|
||||||
|
ovs_assert(shash);
|
||||||
return hmap_count(&shash->map);
|
return hmap_count(&shash->map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include "simap.h"
|
#include "simap.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static size_t hash_name(const char *, size_t length);
|
static size_t hash_name(const char *, size_t length);
|
||||||
static struct simap_node *simap_find__(const struct simap *,
|
static struct simap_node *simap_find__(const struct simap *,
|
||||||
@@ -84,6 +85,7 @@ simap_is_empty(const struct simap *simap)
|
|||||||
size_t
|
size_t
|
||||||
simap_count(const struct simap *simap)
|
simap_count(const struct simap *simap)
|
||||||
{
|
{
|
||||||
|
ovs_assert(simap);
|
||||||
return hmap_count(&simap->map);
|
return hmap_count(&simap->map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -300,6 +300,7 @@ smap_is_empty(const struct smap *smap)
|
|||||||
size_t
|
size_t
|
||||||
smap_count(const struct smap *smap)
|
smap_count(const struct smap *smap)
|
||||||
{
|
{
|
||||||
|
ovs_assert(smap);
|
||||||
return hmap_count(&smap->map);
|
return hmap_count(&smap->map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user