Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/majn/telegram-purple.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormjentsch <mtthsjntsch@gmail.com>2017-02-11 14:44:45 +0300
committermjentsch <mtthsjntsch@gmail.com>2017-02-11 14:51:33 +0300
commit4980fa460c86fabb75507303dfaba263e767d2c9 (patch)
treee79b346d202bdacb5ce32f595fe7e2ba0ee6157e /tgp-blist.c
parentd8a040b5d5bdfd9cf08808710cd1b8cffd018734 (diff)
Fix crash on duplicated peer name in peer tree
Diffstat (limited to 'tgp-blist.c')
-rw-r--r--tgp-blist.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/tgp-blist.c b/tgp-blist.c
index 49379da..fb1bc26 100644
--- a/tgp-blist.c
+++ b/tgp-blist.c
@@ -200,13 +200,13 @@ PurpleGroup *tgp_blist_group_init (const char *name) {
char *tgp_blist_create_print_name (struct tgl_state *TLS, tgl_peer_id_t id, const char *a1, const char *a2,
const char *a3, const char *a4) {
-
+
// libtgl passes 0 for all unused strings, therefore the last passed string will always be followed
// by a NULL-termination as expected
gchar *name = g_strjoin (" ", a1, a2, a3, a4, NULL);
-
+
// When the user doesn't provide some input (like last name) ugly trailing or leading
- // whitespaces may occur due to empty strings in the join operator
+ // whitespaces may occur due to empty strings in the g_strjoin arguments
name = g_strstrip(name);
/* Assure that all print_names are unique by checking the following conditions:
@@ -215,17 +215,34 @@ char *tgp_blist_create_print_name (struct tgl_state *TLS, tgl_peer_id_t id, cons
2. No BlistNode with that name should exists unless it is already corresponding to this peer ID. The rationale is
that this prpl uses the first print_name as permanent name for each user. Therefore it must be assured that no
foreign user will ever take this exact name again, otherwise the current users actions might be associated
- with the old BlistNode. */
+ with the old BlistNode.
+ 3. Assure that the print name isn't already stored in the peer_by_name_tree.
+ */
int i = 0;
gchar *n = NULL;
+
tgl_peer_id_t *id2 = tgp_blist_lookup_get_id (TLS, name);
+ if ( !id2) {
+ tgl_peer_t *tmpP = tgl_peer_get_by_name (TLS, name);
+ if (tmpP) {
+ id2 = &tmpP->id;
+ }
+ }
+
while (id2 && tgl_get_peer_id (*id2) != tgl_get_peer_id (id)) {
if (n) {
g_free (n);
}
n = g_strdup_printf ("%s #%d", name, ++ i);
debug ("resolving duplicate for %s, assigning: %s", name, n);
+
id2 = tgp_blist_lookup_get_id (TLS, n);
+ if ( !id2) {
+ tgl_peer_t *tmpP = tgl_peer_get_by_name(TLS, n);
+ if (tmpP) {
+ id2 = &tmpP->id;
+ }
+ }
}
if (n) {
g_free (name);