Ticket #1154: patch_message_unknown_participant2.txt

File patch_message_unknown_participant2.txt, 1.2 KB (added by celestin.matte@…, at 2014-04-27T12:37:46Z)

Better patch: avoid possible segfault condition

Line 
1=== modified file 'protocols/bee_chat.c'
2--- protocols/bee_chat.c        2010-09-05 23:30:40 +0000
3+++ protocols/bee_chat.c        2014-04-27 12:35:33 +0000
4@@ -99,8 +99,16 @@
5       
6        if( bu && bee->ui->chat_msg )
7                bee->ui->chat_msg( bee, c, bu, msg, sent_at );
8-       else
9+       else if( bee->ui->chat_msg ) {
10+               /* The user is not present in the room. Let's add him for
11+                *  this one message, then remove him.
12+                */
13+               bu = bee_user_new( bee, c->ic, who, BEE_USER_LOCAL );
14+               bee->ui->chat_msg( bee, c, bu, msg, sent_at );
15+               bee->ui->chat_remove_user( bee, c, bu );
16+       } else {
17                imcb_chat_log( c, "Message from unknown participant %s: %s", who, msg );
18+       }
19 }
20 
21 void imcb_chat_log( struct groupchat *c, char *format, ... )
22
23=== modified file 'protocols/jabber/conference.c'
24--- protocols/jabber/conference.c       2013-02-21 19:15:59 +0000
25+++ protocols/jabber/conference.c       2014-04-27 12:00:47 +0000
26@@ -409,7 +409,7 @@
27                        /* This can happen too, at least when receiving a backlog when
28                           just joining a channel. */
29                        if( chat )
30-                               imcb_chat_log( chat, "Message from unknown participant %s: %s", nick, body->text );
31+                               imcb_chat_msg( chat, nick, body->text, 0, jabber_get_timestamp( node ) );
32                        else
33                                imcb_log( ic, "Groupchat message from unknown JID %s: %s", s, body->text );
34                }
35