plugins: add more arg checks to code and tests
authorJussi Laako <jussi.laako@linux.intel.com>
Fri, 2 Jan 2015 16:39:26 +0000 (18:39 +0200)
committerJussi Laako <jussi.laako@linux.intel.com>
Fri, 2 Jan 2015 16:39:26 +0000 (18:39 +0200)
src/daemon/plugins/gsignond-plugin-proxy-factory.c
test/plugins/passwordplugintest.c
test/plugins/pluginproxytest.c

index a195a2b..8aa8412 100644 (file)
@@ -390,6 +390,8 @@ const gchar**
 gsignond_plugin_proxy_factory_get_plugin_types(
    GSignondPluginProxyFactory* factory)
 {
+    g_return_val_if_fail(factory, NULL);
+
        if (factory->methods == NULL) {
                _enumerate_plugins (factory);
        }
@@ -400,6 +402,7 @@ const gchar**
 gsignond_plugin_proxy_factory_get_plugin_mechanisms(
    GSignondPluginProxyFactory* factory, const gchar* plugin_type)
 {
+    g_return_val_if_fail(factory && plugin_type, NULL);
     g_return_val_if_fail(factory->methods_to_mechanisms, NULL);
 
     if (factory->methods == NULL) {
index 5459544..1d06c60 100644 (file)
 
 static void check_plugin(GSignondPlugin* plugin)
 {
-    gchar* type;
-    gchar** mechanisms;
+    gchar* type = NULL;
+    gchar** mechanisms = NULL;
 
     fail_if(plugin == NULL);
     
     g_object_get(plugin, "type", &type, "mechanisms", &mechanisms, NULL);
     
+    fail_if(type == NULL || mechanisms == NULL);
     fail_unless(g_strcmp0(type, "password") == 0);
     fail_unless(g_strcmp0(mechanisms[0], "password") == 0);
     fail_unless(mechanisms[1] == NULL);
index 9b2ced2..20535b0 100644 (file)
@@ -434,7 +434,7 @@ START_TEST (test_pluginproxyfactory_methods_and_mechanisms)
     fail_if(factory == NULL);
     const gchar *pass_method = NULL;
     const gchar** pmethods = NULL;
-    
+
     const gchar** methods = gsignond_plugin_proxy_factory_get_plugin_types(
             factory);
     fail_if(methods == NULL);
@@ -446,10 +446,12 @@ START_TEST (test_pluginproxyfactory_methods_and_mechanisms)
         }
         pmethods++;
     }
+    fail_if(pass_method == NULL);
     const gchar** mechanisms =
             gsignond_plugin_proxy_factory_get_plugin_mechanisms(factory,
                     pass_method);
     fail_if(mechanisms == NULL);
+    fail_if(mechanisms[0] == NULL);
     fail_if(strcmp(mechanisms[0], "password") != 0);
     fail_if(mechanisms[1] != NULL);