Added TYPE='less parsing support to SilcVCard.
authorPekka Riikonen <priikone@silcnet.org>
Wed, 16 Oct 2002 14:45:53 +0000 (14:45 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 16 Oct 2002 14:45:53 +0000 (14:45 +0000)
Fixed double free in hash table foreach function if entry is
deleted in the callback.

CHANGES
lib/silcutil/silchashtable.c
lib/silcutil/silcvcard.c

diff --git a/CHANGES b/CHANGES
index f540db9571cb1f9812471d9bc96a0c455a9b0923..78a17aa7b581159362d25e76d9cbe88d9e7d8522 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,12 @@
+Wed Oct 16 17:40:56 EEST 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * 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 <priikone@silcnet.org>
 
        * Added silc_attribute_get_verify_data to return the signature
index eb3b180e1141574cba37878e75f8aef9db7ef8aa..696a0220f4c331744216bf9330a3f326276b8b07 100644 (file)
@@ -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;
     }
   }
 
index 0f9479c15c526a1ee856f483ff1a3ec6c9a79e81..59ae5cfd716f855c9434cc8f056f680f12eee25c 100644 (file)
@@ -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 */