From: Pekka Riikonen Date: Wed, 16 Oct 2002 14:45:53 +0000 (+0000) Subject: Added TYPE='less parsing support to SilcVCard. X-Git-Tag: silc.client.0.9.6~8 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=05d1b9a102b233365185b459ce3291b681c4df5b Added TYPE='less parsing support to SilcVCard. Fixed double free in hash table foreach function if entry is deleted in the callback. --- diff --git a/CHANGES b/CHANGES index f540db95..78a17aa7 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +Wed Oct 16 17:40:56 EEST 2002 Pekka Riikonen + + * Added support for parsing VCard fields that do not have + the TYPE= for types. Affected file lib/silcutil/silcvcard.c. + + * Fixed a double free bug in hash table foreach function + if the entry was deleted in the foreach callback. Affected + file lib/silcutil/silchashtable.c. + Tue Oct 15 18:05:24 EEST 2002 Pekka Riikonen * Added silc_attribute_get_verify_data to return the signature diff --git a/lib/silcutil/silchashtable.c b/lib/silcutil/silchashtable.c index eb3b180e..696a0220 100644 --- a/lib/silcutil/silchashtable.c +++ b/lib/silcutil/silchashtable.c @@ -72,7 +72,7 @@ struct SilcHashTableStruct { void *hash_user_context; void *compare_user_context; void *destructor_user_context; - bool auto_rehash; + unsigned int auto_rehash : 1; }; /* Prime sizes for the hash table. The size of the table will always @@ -214,7 +214,7 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key, SilcHashForeach foreach, void *foreach_user_context) { - SilcHashTableEntry *entry, *tmp; + SilcHashTableEntry e, tmp; bool auto_rehash, found = FALSE; SilcUInt32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context); @@ -225,28 +225,24 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key, auto_rehash = ht->auto_rehash; ht->auto_rehash = FALSE; - entry = &ht->table[i]; + e = ht->table[i]; if (compare) { - while (*entry) { - if (compare((*entry)->key, key, compare_user_context)) { - tmp = &(*entry)->next; - foreach((*entry)->key, (*entry)->context, foreach_user_context); + while (e) { + tmp = e->next; + if (compare(e->key, key, compare_user_context)) { found = TRUE; - entry = tmp; - continue; + foreach(e->key, e->context, foreach_user_context); } - entry = &(*entry)->next; + e = tmp; } } else { - while (*entry) { - if ((*entry)->key == key) { - tmp = &(*entry)->next; - foreach((*entry)->key, (*entry)->context, foreach_user_context); + while (e) { + tmp = e->next; + if (e->key == key) { found = TRUE; - entry = tmp; - continue; + foreach(e->key, e->context, foreach_user_context); } - entry = &(*entry)->next; + e = tmp; } } diff --git a/lib/silcutil/silcvcard.c b/lib/silcutil/silcvcard.c index 0f9479c1..59ae5cfd 100644 --- a/lib/silcutil/silcvcard.c +++ b/lib/silcutil/silcvcard.c @@ -133,14 +133,17 @@ unsigned char *silc_vcard_encode(SilcVCard vcard, SilcUInt32 *vcard_len) continue; \ } -/* Take on TYPE= token and prepare for next token */ -#define VCARD_TYPETOKEN(x) \ - if (!(x)) { \ - int tmpi; \ - (x) = silc_memdup(val + off + 5, i - off - 5 - 1); \ - tmpi = off + 5 + strlen((x)) + 1; \ - off = i; \ - i = tmpi; \ +/* Take on TYPE= token and prepare for next token, accept the + type also without TYPE= as it is possible */ +#define VCARD_TYPETOKEN(x) \ + if (!(x)) { \ + int tmpi = 0; \ + if (!strcasecmp(val + off, "TYPE=")) \ + tmpi = 5; \ + (x) = silc_memdup(val + off + tmpi, i - off - tmpi - 1); \ + tmpi = off + tmpi + strlen((x)) + 1; \ + off = i; \ + i = tmpi; \ } /* Take last token */