[libpeas] Fix handling of g_callable_info_get_n_args()
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Fix handling of g_callable_info_get_n_args()
- Date: Thu, 11 Nov 2010 17:30:33 +0000 (UTC)
commit a2f98e51140286ff18a4442e2e7c39905afe40fb
Author: Dan Williams <dcbw redhat com>
Date: Thu Nov 11 11:27:23 2010 -0600
Fix handling of g_callable_info_get_n_args()
g_callable_get_n_args() returns gint but libpeas treats the return value as
guint in a few places. If introspection is somewhat broken (and thus the
callable info that libpeas passes to g_callable_get_n_args() is NULL) then
libpeas will execute a couple for-loops from 0 to GUINT_MAX due to the mistype.
Also protect a few more paths that might get triggered due to missing
introspection data.
https://bugzilla.gnome.org/show_bug.cgi?id=633907
libpeas/peas-extension-set.c | 8 +++++++-
libpeas/peas-extension-subclasses.c | 4 +++-
libpeas/peas-extension.c | 5 ++++-
libpeas/peas-introspection.c | 12 +++++++++---
loaders/seed/peas-extension-seed.c | 7 ++++++-
5 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/libpeas/peas-extension-set.c b/libpeas/peas-extension-set.c
index e306316..d21e8b5 100644
--- a/libpeas/peas-extension-set.c
+++ b/libpeas/peas-extension-set.c
@@ -497,12 +497,18 @@ peas_extension_set_call_valist (PeasExtensionSet *set,
{
GICallableInfo *callable_info;
GIArgument *args;
+ gint n_args;
g_return_val_if_fail (PEAS_IS_EXTENSION_SET (set), FALSE);
g_return_val_if_fail (method_name != NULL, FALSE);
callable_info = peas_gi_get_method_info (set->priv->exten_type, method_name);
- args = g_newa (GIArgument, g_callable_info_get_n_args (callable_info));
+ g_return_val_if_fail (callable_info != NULL, FALSE);
+
+ n_args = g_callable_info_get_n_args (callable_info);
+ g_return_val_if_fail (n_args >= 0, FALSE);
+
+ args = g_newa (GIArgument, n_args);
peas_gi_valist_to_arguments (callable_info, va_args, args, NULL);
return peas_extension_set_callv (set, method_name, args);
diff --git a/libpeas/peas-extension-subclasses.c b/libpeas/peas-extension-subclasses.c
index 9231eca..0f48c11 100644
--- a/libpeas/peas-extension-subclasses.c
+++ b/libpeas/peas-extension-subclasses.c
@@ -59,7 +59,7 @@ handle_method_impl (ffi_cif *cif,
GIArgInfo *arg_info;
GITypeInfo *type_info;
GITypeInfo *return_type_info;
- guint n_args, i;
+ gint n_args, i;
PeasExtension *instance;
GIArgument *arguments;
GIArgument return_value;
@@ -68,6 +68,7 @@ handle_method_impl (ffi_cif *cif,
g_assert (PEAS_IS_EXTENSION (instance));
n_args = g_callable_info_get_n_args (impl->info);
+ g_return_if_fail (n_args < 1);
arguments = g_newa (GIArgument, n_args-1);
for (i = 1; i < n_args; i++)
@@ -191,6 +192,7 @@ implement_interface_methods (gpointer iface,
g_type_name (exten_type), g_type_name (proxy_type));
iface_info = g_irepository_find_by_gtype (NULL, exten_type);
+ g_return_if_fail (iface_info != NULL);
g_return_if_fail (g_base_info_get_type (iface_info) == GI_INFO_TYPE_INTERFACE);
n_vfuncs = g_interface_info_get_n_vfuncs (iface_info);
diff --git a/libpeas/peas-extension.c b/libpeas/peas-extension.c
index 83f0e5f..63accb1 100644
--- a/libpeas/peas-extension.c
+++ b/libpeas/peas-extension.c
@@ -217,6 +217,7 @@ peas_extension_call_valist (PeasExtension *exten,
GIArgument retval;
gpointer retval_ptr;
gboolean ret;
+ gint n_args;
g_return_val_if_fail (PEAS_IS_EXTENSION (exten), FALSE);
g_return_val_if_fail (method_name != NULL, FALSE);
@@ -225,7 +226,9 @@ peas_extension_call_valist (PeasExtension *exten,
if (callable_info == NULL)
return FALSE;
- gargs = g_newa (GIArgument, g_callable_info_get_n_args (callable_info));
+ n_args = g_callable_info_get_n_args (callable_info);
+ g_return_val_if_fail (n_args >= 0, FALSE);
+ gargs = g_newa (GIArgument, n_args);
peas_gi_valist_to_arguments (callable_info, args, gargs, &retval_ptr);
ret = peas_extension_callv (exten, method_name, gargs, &retval);
diff --git a/libpeas/peas-introspection.c b/libpeas/peas-introspection.c
index e93ec51..705c21a 100644
--- a/libpeas/peas-introspection.c
+++ b/libpeas/peas-introspection.c
@@ -31,12 +31,14 @@ peas_gi_valist_to_arguments (GICallableInfo *callable_info,
GIArgument *arguments,
gpointer *return_value)
{
- guint i, n_args;
+ gint i, n_args;
GIArgInfo *arg_info;
GITypeInfo *arg_type_info;
GITypeInfo *retval_info;
GIArgument *cur_arg;
+ g_return_if_fail (callable_info != NULL);
+
n_args = g_callable_info_get_n_args (callable_info);
for (i = 0; i < n_args; i++)
@@ -144,9 +146,11 @@ peas_gi_split_in_and_out_arguments (GICallableInfo *callable_info,
GIArgument *out_args,
guint *n_out_args)
{
- guint n_args, i;
+ gint n_args, i;
GIArgInfo *arg_info;
+ g_return_if_fail (callable_info != NULL);
+
n_args = g_callable_info_get_n_args (callable_info);
for (i = 0; i < n_args; i++)
@@ -347,7 +351,8 @@ peas_method_apply (GObject *instance,
GIArgument *return_value)
{
GICallableInfo *func_info;
- guint n_args, n_in_args, n_out_args;
+ gint n_args;
+ guint n_in_args, n_out_args;
GIArgument *in_args, *out_args;
gboolean ret = TRUE;
GError *error = NULL;
@@ -357,6 +362,7 @@ peas_method_apply (GObject *instance,
return FALSE;
n_args = g_callable_info_get_n_args (func_info);
+ g_return_val_if_fail (n_args >= 0, FALSE);
n_in_args = 0;
n_out_args = 0;
diff --git a/loaders/seed/peas-extension-seed.c b/loaders/seed/peas-extension-seed.c
index e5327bb..ab8e999 100644
--- a/loaders/seed/peas-extension-seed.c
+++ b/loaders/seed/peas-extension-seed.c
@@ -235,7 +235,8 @@ peas_extension_seed_call (PeasExtension *exten,
SeedValue js_method;
GICallableInfo *func_info;
GITypeInfo *retval_info;
- guint n_args, n_in_args, n_out_args, i;
+ gint n_args;
+ guint n_in_args, n_out_args, i;
SeedValue *js_in_args;
OutArg *out_args;
SeedValue js_ret, val;
@@ -268,7 +269,11 @@ peas_extension_seed_call (PeasExtension *exten,
/* Prepare the arguments */
func_info = peas_gi_get_method_info (exten_type, method_name);
+ if (func_info == NULL)
+ return FALSE;
+
n_args = g_callable_info_get_n_args (func_info);
+ g_return_val_if_fail (n_args >= 0, FALSE);
n_in_args = 0;
n_out_args = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]