From 23f36bda1e654aedde30329353fa7423ac51c4bd Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 6 Aug 2012 11:57:35 +0100 Subject: [PATCH 2/3] */status.c: don't crash if form fields have unexpected types FORM_TYPE should be hidden, type should be text-single, and name and caps should be text-multi. This is significant because if the types of name and caps are not explicitly specified in the message, Wocky will guess. If there is only one value, it will guess text-single, and the GValue will contain G_TYPE_STRING, not G_TYPE_STRV, causing a crash when we call g_value_get_boxed. --- gabble/status.c | 20 ++++++++++++-------- salut/status.c | 22 +++++++++++++--------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/gabble/status.c b/gabble/status.c index 8b254f6..9dcd7e6 100644 --- a/gabble/status.c +++ b/gabble/status.c @@ -341,25 +341,28 @@ contact_capabilities_changed (YtstStatus *self, gchar **yts_caps; type = g_hash_table_lookup (form->fields, "FORM_TYPE"); - form_type = g_value_get_string (type->default_value); if (type == NULL - || !g_str_has_prefix (form_type, SERVICE_PREFIX)) - { - continue; - } + || type->type != WOCKY_DATA_FORM_FIELD_TYPE_HIDDEN) + continue; + + form_type = g_value_get_string (type->default_value); + + if (!g_str_has_prefix (form_type, SERVICE_PREFIX)) + continue; service = form_type + strlen (SERVICE_PREFIX); /* service type */ tmp = g_hash_table_lookup (form->fields, "type"); - if (tmp == NULL) + if (tmp == NULL || tmp->type != WOCKY_DATA_FORM_FIELD_TYPE_TEXT_SINGLE) continue; yts_service_name = g_value_dup_string (tmp->default_value); /* name map */ tmp = g_hash_table_lookup (form->fields, "name"); - if (tmp != NULL && tmp->default_value != NULL) + if (tmp != NULL && tmp->default_value != NULL && + tmp->type == WOCKY_DATA_FORM_FIELD_TYPE_TEXT_MULTI) { yts_name_map = get_name_map_from_strv ( g_value_get_boxed (tmp->default_value)); @@ -371,7 +374,8 @@ contact_capabilities_changed (YtstStatus *self, /* caps */ tmp = g_hash_table_lookup (form->fields, "capabilities"); - if (tmp != NULL && tmp->default_value != NULL) + if (tmp != NULL && tmp->default_value != NULL && + tmp->type == WOCKY_DATA_FORM_FIELD_TYPE_TEXT_MULTI) { yts_caps = g_strdupv (tmp->raw_value_contents); } diff --git a/salut/status.c b/salut/status.c index d628308..b65d577 100644 --- a/salut/status.c +++ b/salut/status.c @@ -344,25 +344,28 @@ contact_capabilities_changed (YtstStatus *self, gchar **yts_caps; type = g_hash_table_lookup (form->fields, "FORM_TYPE"); - form_type = g_value_get_string (type->default_value); if (type == NULL - || !g_str_has_prefix (form_type, SERVICE_PREFIX)) - { - continue; - } + || type->type != WOCKY_DATA_FORM_FIELD_TYPE_HIDDEN) + continue; + + form_type = g_value_get_string (type->default_value); + + if (!g_str_has_prefix (form_type, SERVICE_PREFIX)) + continue; service = form_type + strlen (SERVICE_PREFIX); /* service type */ tmp = g_hash_table_lookup (form->fields, "type"); - if (tmp == NULL) + if (tmp == NULL || tmp->type != WOCKY_DATA_FORM_FIELD_TYPE_TEXT_SINGLE) continue; yts_service_name = g_value_dup_string (tmp->default_value); - /* name map */ tmp = g_hash_table_lookup (form->fields, "name"); - if (tmp != NULL && tmp->default_value != NULL) + + if (tmp != NULL && tmp->default_value != NULL && + tmp->type == WOCKY_DATA_FORM_FIELD_TYPE_TEXT_MULTI) { yts_name_map = get_name_map_from_strv ( g_value_get_boxed (tmp->default_value)); @@ -374,7 +377,8 @@ contact_capabilities_changed (YtstStatus *self, /* caps */ tmp = g_hash_table_lookup (form->fields, "capabilities"); - if (tmp != NULL && tmp->default_value != NULL) + if (tmp != NULL && tmp->default_value != NULL && + tmp->type == WOCKY_DATA_FORM_FIELD_TYPE_TEXT_MULTI) { yts_caps = g_strdupv (tmp->raw_value_contents); } -- 1.7.10.4