[libgweather] GWeatherLocation: be forgiving if the variant is of the wrong type
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather] GWeatherLocation: be forgiving if the variant is of the wrong type
- Date: Sun, 2 Dec 2012 19:08:51 +0000 (UTC)
commit d81d1aeb66c64915fece2f0473bf07231f0cfc35
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun Dec 2 19:44:35 2012 +0100
GWeatherLocation: be forgiving if the variant is of the wrong type
Check the type when deserializing, and fail early instead of crashing
by accessing uninitialized data.
libgweather/gweather-location.c | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 0a78f96..a2a5f4d 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -970,6 +970,11 @@ gweather_location_format_one_deserialize (GWeatherLocation *world,
GList *candidates, *l;
GWeatherLocation *found;
+ /* This one instead is a critical, because format is specified in
+ the containing variant */
+ g_return_val_if_fail (g_variant_is_of_type (variant,
+ G_VARIANT_TYPE ("(ssbm(dd)m(dd))")), NULL);
+
g_variant_get (variant, "(&s&sbm(dd)m(dd))", &name, &station_code, &is_city,
&latlon_valid, &latitude, &longitude,
&parent_latlon_valid, &parent_latitude, &parent_longitude);
@@ -1051,6 +1056,14 @@ gweather_location_deserialize (GWeatherLocation *world,
GWeatherLocation *loc;
int format;
+ g_return_val_if_fail (world != NULL, NULL);
+ g_return_val_if_fail (serialized != NULL, NULL);
+
+ /* This is not a critical error, because the serialization format
+ is not public, so apps can't check this before calling */
+ if (!g_variant_is_of_type (serialized, G_VARIANT_TYPE ("(uv)")))
+ return NULL;
+
g_variant_get (serialized, "(uv)", &format, &v);
if (format == FORMAT)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]