hal: Branch 'master'
Danny Kukawka
dkukawka at kemper.freedesktop.org
Tue Aug 28 10:23:39 PDT 2007
libhal/libhal.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 53 insertions(+), 8 deletions(-)
New commits:
diff-tree 7deca6dbcdd21325077943ca65ba88db5be6040b (from 223efeb9ded17135935dc67cdaf4e64e98bfbcd2)
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Tue Aug 28 19:23:17 2007 +0200
add more parameter checks to libhal
This patch adds some more parameter check to some of the libhal
functions to avoid possible trouble (e.g. in libhal_free_property_set()).
diff --git a/libhal/libhal.c b/libhal/libhal.c
index cb979b0..0f22543 100644
--- a/libhal/libhal.c
+++ b/libhal/libhal.c
@@ -541,6 +541,9 @@ key_sort (LibHalProperty *a, LibHalPrope
void
libhal_property_set_sort (LibHalPropertySet *set)
{
+ if (set == NULL)
+ return;
+
HASH_SORT (set->properties, key_sort);
}
@@ -555,6 +558,9 @@ libhal_free_property_set (LibHalProperty
{
LibHalProperty *p;
+ if (set == NULL)
+ return;
+
for (p = set->properties; p != NULL; p=p->hh.next) {
HASH_DELETE (hh, set->properties, p);
free (p->key);
@@ -581,8 +587,7 @@ libhal_property_set_get_num_elems (LibHa
unsigned int num_elems;
LibHalProperty *p;
- if (set == NULL)
- return 0;
+ LIBHAL_CHECK_PARAM_VALID(set, "*set", 0);
num_elems = 0;
for (p = set->properties; p != NULL; p = p->hh.next)
@@ -596,6 +601,9 @@ property_set_lookup (const LibHalPropert
{
LibHalProperty *p;
+ LIBHAL_CHECK_PARAM_VALID(set, "*set", NULL);
+ LIBHAL_CHECK_PARAM_VALID(key, "*key", NULL);
+
HASH_FIND_STR (set->properties, key, p);
return p;
}
@@ -614,6 +622,11 @@ LibHalPropertyType
libhal_ps_get_type (const LibHalPropertySet *set, const char *key)
{
LibHalProperty *p = property_set_lookup (set, key);
+
+ LIBHAL_CHECK_PARAM_VALID(set, "*set", LIBHAL_PROPERTY_TYPE_INVALID);
+ LIBHAL_CHECK_PARAM_VALID(key, "*key", LIBHAL_PROPERTY_TYPE_INVALID);
+
+ p = property_set_lookup (set, key);
if (p) return p->type;
else return LIBHAL_PROPERTY_TYPE_INVALID;
}
@@ -632,7 +645,12 @@ libhal_ps_get_type (const LibHalProperty
const char *
libhal_ps_get_string (const LibHalPropertySet *set, const char *key)
{
- LibHalProperty *p = property_set_lookup (set, key);
+ LibHalProperty *p;
+
+ LIBHAL_CHECK_PARAM_VALID(set, "*set", NULL);
+ LIBHAL_CHECK_PARAM_VALID(key, "*key", NULL);
+
+ p = property_set_lookup (set, key);
if (p && p->type == LIBHAL_PROPERTY_TYPE_STRING)
return p->v.str_value;
else return NULL;
@@ -650,7 +668,12 @@ libhal_ps_get_string (const LibHalPrope
dbus_int32_t
libhal_ps_get_int32 (const LibHalPropertySet *set, const char *key)
{
- LibHalProperty *p = property_set_lookup (set, key);
+ LibHalProperty *p;
+
+ LIBHAL_CHECK_PARAM_VALID(set, "*set", 0);
+ LIBHAL_CHECK_PARAM_VALID(key, "*key", 0);
+
+ p = property_set_lookup (set, key);
if (p && p->type == LIBHAL_PROPERTY_TYPE_INT32)
return p->v.int_value;
else return 0;
@@ -668,7 +691,12 @@ libhal_ps_get_int32 (const LibHalPropert
dbus_uint64_t
libhal_ps_get_uint64 (const LibHalPropertySet *set, const char *key)
{
- LibHalProperty *p = property_set_lookup (set, key);
+ LibHalProperty *p;
+
+ LIBHAL_CHECK_PARAM_VALID(set, "*set", 0);
+ LIBHAL_CHECK_PARAM_VALID(key, "*key", 0);
+
+ p = property_set_lookup (set, key);
if (p && p->type == LIBHAL_PROPERTY_TYPE_UINT64)
return p->v.uint64_value;
else return 0;
@@ -686,7 +714,12 @@ libhal_ps_get_uint64 (const LibHalProper
double
libhal_ps_get_double (const LibHalPropertySet *set, const char *key)
{
- LibHalProperty *p = property_set_lookup (set, key);
+ LibHalProperty *p;
+
+ LIBHAL_CHECK_PARAM_VALID(set, "*set", 0.0);
+ LIBHAL_CHECK_PARAM_VALID(key, "*key", 0.0);
+
+ p = property_set_lookup (set, key);
if (p && p->type == LIBHAL_PROPERTY_TYPE_DOUBLE)
return p->v.double_value;
else return 0.0;
@@ -704,7 +737,12 @@ libhal_ps_get_double (const LibHalProper
dbus_bool_t
libhal_ps_get_bool (const LibHalPropertySet *set, const char *key)
{
- LibHalProperty *p = property_set_lookup (set, key);
+ LibHalProperty *p;
+
+ LIBHAL_CHECK_PARAM_VALID(set, "*set", FALSE);
+ LIBHAL_CHECK_PARAM_VALID(key, "*key", FALSE);
+
+ p = property_set_lookup (set, key);
if (p && p->type == LIBHAL_PROPERTY_TYPE_BOOLEAN)
return p->v.bool_value;
else return FALSE;
@@ -722,7 +760,12 @@ libhal_ps_get_bool (const LibHalProperty
const char *const *
libhal_ps_get_strlist (const LibHalPropertySet *set, const char *key)
{
- LibHalProperty *p = property_set_lookup (set, key);
+ LibHalProperty *p;
+
+ LIBHAL_CHECK_PARAM_VALID(set, "*set", NULL);
+ LIBHAL_CHECK_PARAM_VALID(key, "*key", NULL);
+
+ p = property_set_lookup (set, key);
if (p && p->type == LIBHAL_PROPERTY_TYPE_STRLIST)
return (const char *const *) p->v.strlist_value;
else return NULL;
@@ -899,6 +942,8 @@ singleton_device_changed (LibHalContext
LibHalPropertySet *set;
const char *udi;
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+
dbus_message_iter_init (msg, &iter);
/* First should be the device UDI */
More information about the hal-commit
mailing list