Merged silc_1_1_branch to trunk.
[silc.git] / lib / silcutil / silcmime.c
index e424d5d3839840021f52ee6b85b4d941e4b6194f..c0817ec0f594d1eaed43c27d1f88fac673929116 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 - 2006 Pekka Riikonen
+  Copyright (C) 2005 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -198,6 +198,7 @@ SilcMime silc_mime_decode(SilcMime mime, const unsigned char *data,
   if (field && strstr(field, "multipart")) {
     char b[1024];
     SilcMime p;
+    unsigned int len;
 
     mime->multiparts = silc_dlist_init();
     if (!mime->multiparts)
@@ -213,7 +214,10 @@ SilcMime silc_mime_decode(SilcMime mime, const unsigned char *data,
     if (!strchr(field, ';'))
       goto err;
     memset(b, 0, sizeof(b));
-    strncat(b, value, strchr(field, ';') - value);
+    len = (unsigned int)(strchr(field, ';') - value);
+    if (len > sizeof(b) - 1)
+      goto err;
+    strncpy(b, value, len);
     if (strchr(b, '"'))
       *strchr(b, '"') = '\0';
     mime->multitype = silc_memdup(b, strlen(b));
@@ -322,7 +326,7 @@ unsigned char *silc_mime_encode(SilcMime mime, SilcUInt32 *encoded_len)
   /* Encode the headers. Order doesn't matter */
   i = 0;
   silc_hash_table_list(mime->fields, &htl);
-  while (silc_hash_table_get(&htl, (void **)&field, (void **)&value)) {
+  while (silc_hash_table_get(&htl, (void *)&field, (void *)&value)) {
     memset(tmp, 0, sizeof(tmp));
     SILC_LOG_DEBUG(("Header %s: %s", field, value));
     silc_snprintf(tmp, sizeof(tmp) - 1, "%s: %s\r\n", field, value);
@@ -342,6 +346,7 @@ unsigned char *silc_mime_encode(SilcMime mime, SilcUInt32 *encoded_len)
   if (silc_buffer_len(&buf)) {
     silc_buffer_put(buffer, buf.head, silc_buffer_len(&buf));
     silc_buffer_pull(buffer, silc_buffer_len(&buf));
+    silc_buffer_purge(&buf);
   }
 
   /* Add data */
@@ -461,7 +466,7 @@ SilcMime silc_mime_assemble(SilcMimeAssembler assembler, SilcMime partial)
 
   /* Find fragments with this ID. */
   if (!silc_hash_table_find(assembler->fragments, (void *)id,
-                           NULL, (void **)&f)) {
+                           NULL, (void *)&f)) {
     /* This is new fragment to new message.  Add to hash table and return. */
     f = silc_hash_table_alloc(0, silc_hash_uint, NULL, NULL, NULL,
                              silc_mime_assemble_dest, NULL, TRUE);
@@ -506,7 +511,7 @@ SilcMime silc_mime_assemble(SilcMimeAssembler assembler, SilcMime partial)
   /* Assemble the complete MIME message now. We get them in order from
      the hash table. */
   for (i = 1; i <= total; i++) {
-    if (!silc_hash_table_find(f, SILC_32_TO_PTR(i), NULL, (void **)&p))
+    if (!silc_hash_table_find(f, SILC_32_TO_PTR(i), NULL, (void *)&p))
       goto err;
 
     /* The fragment is in the data portion of the partial message */
@@ -698,7 +703,7 @@ const char *silc_mime_get_field(SilcMime mime, const char *field)
     return NULL;
 
   if (!silc_hash_table_find(mime->fields, (void *)field,
-                           NULL, (void **)&value))
+                           NULL, (void *)&value))
     return NULL;
 
   return (const char *)value;