diff options
author | dequis <dx@dxzone.com.ar> | 2015-12-20 04:12:21 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-12-20 15:27:50 -0300 |
commit | 0121bae03b6d545ff799f4b02c9b05becac1b78b (patch) | |
tree | 81683443fc75a5213f9c7f37cba16d7d47562157 | |
parent | 6056cc2235b2e9515008da5a07b5617228006365 (diff) | |
download | bitlbee-facebook-0121bae03b6d545ff799f4b02c9b05becac1b78b.tar.gz bitlbee-facebook-0121bae03b6d545ff799f4b02c9b05becac1b78b.tar.bz2 bitlbee-facebook-0121bae03b6d545ff799f4b02c9b05becac1b78b.tar.xz |
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
-rw-r--r-- | facebook/facebook-json.c | 8 |
1 files changed, 7 insertions, 1 deletions
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; } |