Sat, 22 Jun 2013 12:23:18 +0200
MXit: Strip the markup from the custom emoticon Id before checking for the Id in the cache.
If a message is received that contains 2 or more of the same custom
emoticon (and it's not already in the cache), then memory will be leaked.
| libpurple/protocols/mxit/markup.c | file | annotate | diff | comparison | revisions |
--- a/libpurple/protocols/mxit/markup.c Sat Jun 22 11:24:08 2013 +0200 +++ b/libpurple/protocols/mxit/markup.c Sat Jun 22 12:23:18 2013 +0200 @@ -473,7 +473,6 @@ struct RXMsgData* mx = (struct RXMsgData*) user_data; const gchar* data = url_text; unsigned int pos = 0; - char emo[MXIT_MAX_EMO_ID + 1]; int id; char* str; int em_size = 0; @@ -482,9 +481,7 @@ int* intptr = NULL; int res; -#ifdef MXIT_DEBUG_EMO purple_debug_info( MXIT_PLUGIN_ID, "emoticon_returned\n" ); -#endif /* remove request from the async outstanding calls list */ mx->session->async_calls = g_slist_remove( mx->session->async_calls, url_data ); @@ -499,12 +496,8 @@ hex_dump( data, len ); #endif - /* parse out the emoticon */ - pos = 0; - - /* validate the binary data received from the wapsite */ + /* validate that the returned data starts with the magic constant that indicates it is a custom emoticon */ if ( memcmp( MXIT_FRAME_MAGIC, &data[pos], strlen( MXIT_FRAME_MAGIC ) ) != 0 ) { - /* bad data, magic constant is wrong */ purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad magic)\n" ); goto done; } @@ -512,16 +505,14 @@ /* validate the image frame desc byte */ if ( data[pos] != '\x6F' ) { - /* bad frame desc */ purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad frame desc)\n" ); goto done; } pos++; - /* get the data length */ + /* get the frame image data length */ res = asn_getlength( &data[pos], &em_size ); if ( res <= 0 ) { - /* bad frame length */ purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad frame length)\n" ); goto done; } @@ -533,7 +524,6 @@ /* utf-8 (emoticon name) */ res = asn_getUtf8( &data[pos], 0x0C, &str ); if ( res <= 0 ) { - /* bad utf-8 string */ purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad name string)\n" ); goto done; } @@ -547,7 +537,6 @@ /* utf-8 (emoticon shortcut) */ res = asn_getUtf8( &data[pos], 0x81, &str ); if ( res <= 0 ) { - /* bad utf-8 string */ purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad shortcut string)\n" ); goto done; } @@ -559,7 +548,6 @@ /* validate the image data type */ if ( data[pos] != '\x82' ) { - /* bad frame desc */ purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad data type)\n" ); g_free( em_id ); goto done; @@ -579,8 +567,17 @@ purple_debug_info( MXIT_PLUGIN_ID, "read the length '%i'\n", em_size ); #endif + /* strip the mxit markup tags from the emoticon id (eg, .{XY} -> XY) */ + if ( ( em_id[0] == '.' ) && ( em_id[1] == '{' ) ) { + char emo[MXIT_MAX_EMO_ID + 1]; + + parse_emoticon_str( &em_id[2], emo ); + strcpy( em_id, emo ); + } + if ( g_hash_table_lookup( mx->session->iimages, em_id ) ) { /* emoticon found in the table, so ignore this one */ + g_free( em_id ); goto done; } @@ -588,12 +585,6 @@ em_data = g_malloc( em_size ); memcpy( em_data, &data[pos], em_size ); - /* strip the mxit markup tags from the emoticon id */ - if ( ( em_id[0] == '.' ) && ( em_id[1] == '{' ) ) { - parse_emoticon_str( &em_id[2], emo ); - strcpy( em_id, emo ); - } - /* we now have the emoticon, store it in the imagestore */ id = purple_imgstore_add_with_id( em_data, em_size, NULL );