/pidgin/main: 7f8a2f301a82: facebook-json: Ensure data is null t...

dequis dx at dxzone.com.ar
Mon Dec 21 16:38:17 EST 2015

Changeset: 7f8a2f301a8220750ee9f8b29de424749fab01d4
Author:	 dequis <dx at dxzone.com.ar>
Date:	 2015-12-21 16:31 -0500
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/7f8a2f301a82


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


 libpurple/protocols/facebook/json.c |  8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diffs (31 lines):

diff --git a/libpurple/protocols/facebook/json.c b/libpurple/protocols/facebook/json.c
--- a/libpurple/protocols/facebook/json.c
+++ b/libpurple/protocols/facebook/json.c
@@ -258,13 +258,18 @@ fb_json_bldr_add_strf(JsonBuilder *bldr,
 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_free(slice);
 		return NULL;
@@ -272,6 +277,7 @@ fb_json_node_new(const gchar *data, gssi
 	root = json_node_copy(root);
+	g_free(slice);
 	return root;

More information about the Commits mailing list