From 0121bae03b6d545ff799f4b02c9b05becac1b78b Mon Sep 17 00:00:00 2001 From: dequis Date: Sun, 20 Dec 2015 04:12:21 -0300 Subject: 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 --- facebook/facebook-json.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/facebook/facebook-json.c b/facebook/facebook-json.c index 7272b6c..83332b4 100644 --- a/facebook/facebook-json.c +++ b/facebook/facebook-json.c @@ -252,13 +252,18 @@ fb_json_bldr_add_strf(JsonBuilder *bldr, const gchar *name, 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; } @@ -266,6 +271,7 @@ fb_json_node_new(const gchar *data, gssize size, GError **error) root = json_node_copy(root); g_object_unref(prsr); + g_free(slice); return root; } -- cgit v1.2.3