--- a/libpurple/protocols/jabber/caps.c Thu Jun 01 19:09:16 2017 -0500 +++ b/libpurple/protocols/jabber/caps.c Fri Jun 02 15:09:01 2017 -0500 @@ -455,11 +455,7 @@ if (userdata->hash) { gchar *hash = NULL; GChecksumType hash_type = G_CHECKSUM_SHA1; - /* - * TODO: If you add *any* hash here, make sure the checksum buffer - * size in jabber_caps_calculate_hash is large enough. The cipher API - * doesn't seem to offer a "Get the hash size" function(?). - */ + if (g_str_equal(userdata->hash, "sha-1")) { hash_type = G_CHECKSUM_SHA1; } else if (g_str_equal(userdata->hash, "md5")) { @@ -832,8 +828,9 @@ { GChecksum *hash; GList *node; - guint8 checksum[20]; - gsize checksum_size = 20; + guint8 *checksum; + gsize checksum_size; + gchar *ret; if (!info) return NULL; @@ -915,10 +912,16 @@ } } + checksum_size = g_checksum_type_get_length(hash_type); + checksum = g_new(guint8, checksum_size); + /* generate hash */ g_checksum_get_digest(hash, checksum, &checksum_size); - return purple_base64_encode(checksum, checksum_size); + ret = purple_base64_encode(checksum, checksum_size); + g_free(checksum); + + return ret; } void jabber_caps_calculate_own_hash(JabberStream *js) {