pidgin/pidgin

Parents 9e56dcafff40
Children 56c7dbe97266
facebook-json: Ensure data is null terminated for json-glib < 1.0.2

Older json-glib versions had a bug[1] in which the length parameter was
ignored and this error happened if the input was not null-terminated:

JSON data must be UTF-8 encoded

Since these versions are expected to still be around in some distros,
this commit makes a copy with g_strndup() to ensure that it's always
null terminated.

Thanks to advcomp2019 for reporting this bug and finding a test case
where this issue is reproducible every time (receiving events of people
joining or leaving in a groupchat)

[1]: https://bugzilla.gnome.org/show_bug.cgi?id=727755
--- a/libpurple/protocols/facebook/json.c Mon Dec 21 15:15:47 2015 -0500
+++ b/libpurple/protocols/facebook/json.c Mon Dec 21 16:31:00 2015 -0500
@@ -258,13 +258,18 @@
JsonNode *
fb_json_node_new(const gchar *data, gssize size, GError **error)
{
+ gchar *slice;
JsonNode *root;
JsonParser *prsr;
+ /* Ensure data is null terminated for json-glib < 1.0.2 */
+ slice = g_strndup(data, size);
+
prsr = json_parser_new();
- if (!json_parser_load_from_data(prsr, data, size, error)) {
+ if (!json_parser_load_from_data(prsr, slice, size, error)) {
g_object_unref(prsr);
+ g_free(slice);
return NULL;
}
@@ -272,6 +277,7 @@
root = json_node_copy(root);
g_object_unref(prsr);
+ g_free(slice);
return root;
}