int -> SilcUInt32 changes.
authorPekka Riikonen <priikone@silcnet.org>
Sun, 29 Dec 2002 21:27:37 +0000 (21:27 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 29 Dec 2002 21:27:37 +0000 (21:27 +0000)
16 files changed:
apps/silcd/serverconfig.c
lib/silccore/silcargument.c
lib/silccore/silcattrs.c
lib/silccore/silcchannel.c
lib/silccore/silccommand.c
lib/silccore/silcidcache.c
lib/silccore/silcnotify.c
lib/silccore/silcpacket.c
lib/silccore/silcpacket.h
lib/silccore/tests/test_silcargument.c
lib/silcsftp/sftp_util.c
lib/silcske/payload.c
lib/silcske/silcske.c
lib/silcutil/silcbuffmt.c
lib/silcutil/silcconfig.c
lib/silcutil/silcschedule.c

index c3d3a7f3739757339fb5b623874974ce3b5b3968..911caff0dde735085b13ccc4fa628097740cbe6e 100644 (file)
@@ -1431,9 +1431,11 @@ SilcServerConfig silc_server_config_alloc(const char *filename)
         SILC_SERVER_LOG_ERROR(("Error while parsing config file: %s.",
                               silc_config_strerror(ret)));
       linebuf = silc_config_read_line(file, line);
-      SILC_SERVER_LOG_ERROR(("  file %s line %lu:  %s\n", filename,
-                            line, linebuf));
-      silc_free(linebuf);
+      if (linebuf) {
+       SILC_SERVER_LOG_ERROR(("  file %s line %lu:  %s\n", filename,
+                              line, linebuf));
+       silc_free(linebuf);
+      }
     }
     silc_server_config_destroy(config_new);
     return NULL;
index c58a1c9809d2c3e35dda4a7258c8adb40e1ecb53..d492ed742576b6e4442812568c86d0634581f679 100644 (file)
@@ -132,7 +132,7 @@ SilcBuffer silc_argument_payload_encode(SilcUInt32 argc,
 
   len = 0;
   for (i = 0; i < argc; i++)
-    len += 3 + argv_lens[i];
+    len += 3 + (SilcUInt16)argv_lens[i];
 
   buffer = silc_buffer_alloc_size(len);
   if (!buffer)
@@ -143,9 +143,9 @@ SilcBuffer silc_argument_payload_encode(SilcUInt32 argc,
     silc_buffer_format(buffer,
                       SILC_STR_UI_SHORT(argv_lens[i]),
                       SILC_STR_UI_CHAR(argv_types[i]),
-                      SILC_STR_UI_XNSTRING(argv[i], argv_lens[i]),
+                      SILC_STR_UI_XNSTRING(argv[i], (SilcUInt16)argv_lens[i]),
                       SILC_STR_END);
-    silc_buffer_pull(buffer, 3 + argv_lens[i]);
+    silc_buffer_pull(buffer, 3 + (SilcUInt16)argv_lens[i]);
   }
 
   silc_buffer_push(buffer, len);
@@ -161,9 +161,9 @@ SilcBuffer silc_argument_payload_encode_one(SilcBuffer args,
                                            SilcUInt32 arg_type)
 {
   SilcBuffer buffer = args;
-  int len;
+  SilcUInt32 len;
 
-  len = 3 + arg_len;
+  len = 3 + (SilcUInt16)arg_len;
   buffer = silc_buffer_realloc(buffer,
                               (buffer ? buffer->truelen + len : len));
   if (!buffer)
@@ -173,7 +173,7 @@ SilcBuffer silc_argument_payload_encode_one(SilcBuffer args,
   silc_buffer_format(buffer, 
                     SILC_STR_UI_SHORT(arg_len),
                     SILC_STR_UI_CHAR(arg_type),
-                    SILC_STR_UI_XNSTRING(arg, arg_len),
+                    SILC_STR_UI_XNSTRING(arg, (SilcUInt16)arg_len),
                     SILC_STR_END);
   silc_buffer_push(buffer, buffer->data - buffer->head);
 
index fee2c3959b0d19c82565ebdf023ba625bc485265..2ba0117b79e0573bc4568281c989bed98a07bee5 100644 (file)
@@ -46,7 +46,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
 {
   SilcBuffer tmpbuf = NULL;
   unsigned char tmp[4], *str = NULL, *ret;
-  int len;
+  SilcUInt32 len;
 
   /* Encode according to attribute type */
   if (flags & SILC_ATTRIBUTE_FLAG_VALID) {
@@ -70,7 +70,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
     case SILC_ATTRIBUTE_SERVICE:
       {
        SilcAttributeObjService *service = object;
-       int len2;
+       SilcUInt32 len2;
        if (object_size != sizeof(*service))
          return NULL;
        len = strlen(service->address);
@@ -131,7 +131,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
     case SILC_ATTRIBUTE_GEOLOCATION:
       {
        SilcAttributeObjGeo *geo = object;
-       int len1, len2, len3, len4;
+       SilcUInt32 len1, len2, len3, len4;
        if (object_size != sizeof(*geo))
          return NULL;
        len1 = (geo->longitude ? strlen(geo->longitude) : 0);
@@ -162,7 +162,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
     case SILC_ATTRIBUTE_DEVICE_INFO:
       {
        SilcAttributeObjDevice *dev = object;
-       int len1, len2, len3, len4;
+       SilcUInt32 len1, len2, len3, len4;
        if (object_size != sizeof(*dev))
          return NULL;
        len1 = (dev->manufacturer ? strlen(dev->manufacturer) : 0);
@@ -278,7 +278,8 @@ SilcDList silc_attribute_payload_parse(const unsigned char *payload,
   SilcBufferStruct buffer;
   SilcDList list;
   SilcAttributePayload newp;
-  int len, ret;
+  SilcUInt32 len;
+  int ret;
 
   SILC_LOG_DEBUG(("Parsing Attribute Payload list"));
 
@@ -344,9 +345,9 @@ SilcBuffer silc_attribute_payload_encode_data(SilcBuffer attrs,
                                              SilcUInt32 data_len)
 {
   SilcBuffer buffer = attrs;
-  int len;
+  SilcUInt32 len;
 
-  len = 4 + data_len;
+  len = 4 + (SilcUInt16)data_len;
   buffer = silc_buffer_realloc(buffer,
                               (buffer ? buffer->truelen + len : len));
   if (!buffer)
@@ -357,7 +358,7 @@ SilcBuffer silc_attribute_payload_encode_data(SilcBuffer attrs,
                     SILC_STR_UI_CHAR(attribute),
                     SILC_STR_UI_CHAR(flags),
                     SILC_STR_UI_SHORT((SilcUInt16)data_len),
-                    SILC_STR_UI_XNSTRING(data, data_len),
+                    SILC_STR_UI_XNSTRING(data, (SilcUInt16)data_len),
                     SILC_STR_END);
   silc_buffer_push(buffer, buffer->data - buffer->head);
 
index 2c1b7155f69ac76a743d6651d3459434d1a3829a..5c83bbb422801ac4b472c19a18409a4ac8bde860 100644 (file)
@@ -1,24 +1,22 @@
 /*
 
-  silcchannel.c
+  silcchannel.c 
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2001 Pekka Riikonen
+  Copyright (C) 1997 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
 */
-/* Channel Payload, Channel Message Payload and Channel Key Payload 
-   implementations. */
+/* Channel Payload and Channel Key Payload implementations. */
 /* $Id$ */
 
 #include "silcincludes.h"
@@ -89,7 +87,8 @@ SilcDList silc_channel_payload_parse_list(const unsigned char *payload,
   SilcBufferStruct buffer;
   SilcDList list;
   SilcChannelPayload newp;
-  int len, ret;
+  SilcUInt32 len;
+  int ret;
 
   SILC_LOG_DEBUG(("Parsing channel payload list"));
 
index d8470570c205f7cb363b0d0b7d093db4138bf295..a16dfc6fce792b6e0c8edfe1ac0d17265120b219 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silccommand.c
+  silccommand.c 
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2001 Pekka Riikonen
+  Copyright (C) 1997 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -76,6 +75,7 @@ SilcCommandPayload silc_command_payload_parse(const unsigned char *payload,
   }
 
   if (newp->cmd == 0) {
+    SILC_LOG_ERROR(("Incorrect command type in command payload"));
     silc_free(newp);
     return NULL;
   }
@@ -111,6 +111,8 @@ SilcBuffer silc_command_payload_encode(SilcCommand cmd,
 
   if (argc) {
     args = silc_argument_payload_encode(argc, argv, argv_lens, argv_types);
+    if (!args)
+      return NULL;
     len = args->len;
   }
 
@@ -154,7 +156,8 @@ SilcBuffer silc_command_payload_encode_payload(SilcCommandPayload payload)
 
   if (payload->args) {
     args = silc_argument_payload_encode_payload(payload->args);
-    len = args->len;
+    if (args)
+      len = args->len;
     argc = silc_argument_get_arg_num(payload->args);
   }
 
index 19adb9ff83989a48b07d52f2410542198d708b0f..3d6904e74421b00d962d69e55466f92c9240fa0a 100644 (file)
@@ -189,7 +189,11 @@ bool silc_idcache_add(SilcIDCache cache, char *name, void *id,
 static void silc_idcache_destructor(void *key, void *context,
                                    void *user_context)
 {
-  silc_free(context);
+  SilcIDCacheEntry c = context;
+  if (c) {
+    memset(c, 'F', sizeof(*c));
+    silc_free(c);
+  }
 }
 
 /* Delete cache entry from cache. */
@@ -207,7 +211,7 @@ bool silc_idcache_del(SilcIDCache cache, SilcIDCacheEntry old)
   if (old->id)
     ret = silc_hash_table_del(cache->id_table, old->id);
   else
-    silc_free(old);
+    silc_idcache_destructor(NULL, old, NULL);
 
   return ret;
 }
@@ -274,7 +278,7 @@ bool silc_idcache_del_by_context(SilcIDCache cache, void *context)
   if (c->id)
     ret = silc_hash_table_del_by_context(cache->id_table, c->id, c);
   else
-    silc_free(c);
+    silc_idcache_destructor(NULL, c, NULL);
 
   return ret;
 }
@@ -304,6 +308,7 @@ static void silc_idcache_purge_foreach(void *key, void *context,
   SilcIDCache cache = (SilcIDCache)user_context;
   SilcUInt32 curtime = time(NULL);
   SilcIDCacheEntry c = (SilcIDCacheEntry)context;
+  bool ret = FALSE;
 
   if (!context)
     return;
@@ -311,20 +316,23 @@ static void silc_idcache_purge_foreach(void *key, void *context,
   if (c->expire && c->expire < curtime) {
     /* Remove the entry from the hash tables */
     if (c->name)
-      silc_hash_table_del_by_context(cache->name_table, c->name, c);
+      ret = silc_hash_table_del_by_context(cache->name_table, c->name, c);
     if (c->context)
-      silc_hash_table_del(cache->context_table, c->context);
+      ret = silc_hash_table_del(cache->context_table, c->context);
     if (c->id)
-      silc_hash_table_del_by_context_ext(cache->id_table, c->id, c,
-                                        NULL, NULL, NULL, NULL, 
-                                        silc_idcache_destructor_dummy, NULL);
-
-    /* Call the destructor */
-    if (cache->destructor)
-      cache->destructor(cache, c);
-
-    /* Free the entry, it has been deleted from the hash tables */
-    silc_free(c);
+      ret =
+       silc_hash_table_del_by_context_ext(cache->id_table, c->id, c,
+                                          NULL, NULL, NULL, NULL, 
+                                          silc_idcache_destructor_dummy,
+                                          NULL);
+    if (ret == TRUE) {
+      /* Call the destructor */
+      if (cache->destructor)
+       cache->destructor(cache, c);
+
+      /* Free the entry, it has been deleted from the hash tables */
+      silc_idcache_destructor(NULL, c, NULL);
+    }
   }
 }
 
@@ -358,13 +366,14 @@ bool silc_idcache_purge_by_context(SilcIDCache cache, void *context)
       silc_hash_table_del_by_context_ext(cache->id_table, c->id, c,
                                         NULL, NULL, NULL, NULL, 
                                         silc_idcache_destructor_dummy, NULL);
-  
-  /* Call the destructor */
-  if (cache->destructor)
-    cache->destructor(cache, c);
+  if (ret == TRUE) {
+    /* Call the destructor */
+    if (cache->destructor)
+      cache->destructor(cache, c);
 
-  /* Free the entry, it has been deleted from the hash tables */
-  silc_free(c);
+    /* Free the entry, it has been deleted from the hash tables */
+    silc_idcache_destructor(NULL, c, NULL);
+  }
 
   return ret;
 }
index 20a42e9e863c8ac7c8853a57163b346002e7e944..f8a6389a5a4cf6d5361adde0f37ed970b8e752e4 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silcnotify.c
+  silcnotify.c 
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2000 Pekka Riikonen
+  Copyright (C) 2000 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -88,8 +87,8 @@ SilcBuffer silc_notify_payload_encode(SilcNotifyType type, SilcUInt32 argc,
   unsigned char **argv;
   SilcUInt32 *argv_lens = NULL, *argv_types = NULL;
   unsigned char *x;
-  SilcUInt32 x_len;
-  int i, k = 0, len = 0;
+  SilcUInt32 x_len, len = 0;
+  int i, k = 0;
 
   if (argc) {
     argv = silc_calloc(argc, sizeof(unsigned char *));
@@ -161,7 +160,7 @@ SilcBuffer silc_notify_payload_encode_args(SilcNotifyType type,
                                           SilcBuffer args)
 {
   SilcBuffer buffer;
-  int len;
+  SilcUInt32 len;
 
   len = 5 + (args ? args->len : 0);
   buffer = silc_buffer_alloc_size(len);
index 6643945b6007290ab9f93f15d7bf3a7e6625cde4..7bac3681106e2d8282b224cda531b985a7b9d7d8 100644 (file)
@@ -116,7 +116,7 @@ bool silc_packet_assemble(SilcPacketContext *packet, SilcRng rng,
                          const SilcBuffer assembled_packet)
 { 
   unsigned char tmppad[SILC_PACKET_MAX_PADLEN];   
-  int block_len = cipher ? silc_cipher_get_block_len(cipher) : 0;
+  unsigned int block_len = cipher ? silc_cipher_get_block_len(cipher) : 0;
   int i, ret;
 
   SILC_LOG_DEBUG(("Assembling outgoing packet"));
@@ -202,9 +202,9 @@ bool silc_packet_send_prepare(SilcSocketConnection sock,
                              SilcHmac hmac,
                              const SilcBuffer packet)
 { 
-  int totlen;
+  SilcUInt32 totlen;
   unsigned char *oldptr;
-  int mac_len = hmac ? silc_hmac_len(hmac) : 0;
+  unsigned int mac_len = hmac ? silc_hmac_len(hmac) : 0;
 
   if (!packet)
     return FALSE;
@@ -305,7 +305,9 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
                                 void *parser_context)
 {
   SilcPacketParserContext *parse_ctx;
-  int packetlen, paddedlen, mac_len = 0, ret, block_len;
+  SilcUInt16 packetlen;
+  SilcUInt32 paddedlen, mac_len = 0, block_len;
+  int ret;
   bool cont = TRUE;
   unsigned char tmp[SILC_PACKET_MIN_HEADER_LEN], *header;
   unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
@@ -381,8 +383,8 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
       return FALSE;
     parse_ctx->packet = silc_packet_context_alloc();
     parse_ctx->packet->buffer = silc_buffer_alloc_size(paddedlen);
-    parse_ctx->packet->type = header[3];
-    parse_ctx->packet->padlen = header[4];
+    parse_ctx->packet->type = (SilcPacketType)header[3];
+    parse_ctx->packet->padlen = (SilcUInt8)header[4];
     parse_ctx->packet->sequence = sequence++;
     parse_ctx->sock = sock;
     parse_ctx->context = parser_context;
@@ -515,7 +517,7 @@ static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac,
     /* Decrypt rest of the header plus padding */
     if (cipher) {
       SilcUInt16 len;
-      int block_len = silc_cipher_get_block_len(cipher);
+      SilcUInt32 block_len = silc_cipher_get_block_len(cipher);
 
       SILC_LOG_DEBUG(("Decrypting the header"));
 
index 0e15ae438b714ae7a01584a78af24a23942f9d90..b2c9dd2790dc0b121ffc10c5f3919e452aa3dd01 100644 (file)
@@ -335,7 +335,7 @@ typedef bool (*SilcPacketParserCallback)(SilcPacketParserContext
 #define SILC_PACKET_LENGTH(__packetdata, __ret_truelen, __ret_paddedlen) \
 do {                                                                    \
   SILC_GET16_MSB((__ret_truelen), (__packetdata));                      \
-  (__ret_paddedlen) = (__ret_truelen) + (__packetdata)[4];              \
+  (__ret_paddedlen) = (__ret_truelen) + (SilcUInt8)(__packetdata)[4];   \
 } while(0)
 /***/
 
index 58f84659d81f9dabdeff2c2b839e57e79e498ab2..0b36d326a669e3f05c86f41d97ad0199457937aa 100644 (file)
@@ -108,6 +108,13 @@ int main(int argc, char **argv)
   SILC_LOG_DEBUG(("Re-encoding was successful"));
 
 
+  SILC_LOG_DEBUG(("Checking number of arguments"));
+  SILC_LOG_DEBUG(("Number of arguments: %d (expecting %d)",
+                silc_argument_get_arg_num(payload), ARG_NUM + 1));
+  if (silc_argument_get_arg_num(payload) != ARG_NUM + 1)
+    goto out;
+
+
   SILC_LOG_DEBUG(("Traversing the parsed arguments"));
   i = 0;
   a = silc_argument_get_first_arg(payload, &t, &l);
index 2e982d6d6b70a502cfb4f12e886ee03f6ff68d18..dc2f5cff67e19fab735a3a158518b0e0289e298a 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 Pekka Riikonen
+  Copyright (C) 2001 - 2002 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
@@ -133,7 +133,8 @@ SilcSFTPPacket silc_sftp_packet_decode(SilcBuffer packet,
 SilcBuffer silc_sftp_attr_encode(SilcSFTPAttributes attr)
 {
   SilcBuffer buffer;
-  int i, ret, len = 4;
+  int i, ret;
+  SilcUInt32 len = 4;
 
   if (attr->flags & SILC_SFTP_ATTR_SIZE)
     len += 8;
@@ -152,10 +153,9 @@ SilcBuffer silc_sftp_attr_encode(SilcSFTPAttributes attr)
     }
   }
 
-  buffer = silc_buffer_alloc(len);
+  buffer = silc_buffer_alloc_size(len);
   if (!buffer)
     return NULL;
-  silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
 
   silc_buffer_format(buffer, 
                     SILC_STR_UI_INT(attr->flags), 
index 99457a804669daf43d87bffb7326d82d8fe397cc..d7fb301d5e514acfb0ff31626a026d87ee2e7313 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  payload.c
+  payload.c 
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2000 - 2001 Pekka Riikonen
+  Copyright (C) 2000 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -36,10 +35,9 @@ SilcSKEStatus silc_ske_payload_start_encode(SilcSKE ske,
   if (!payload)
     return SILC_SKE_STATUS_ERROR;
 
-  buf = silc_buffer_alloc(payload->len);
+  buf = silc_buffer_alloc_size(payload->len);
   if (!buf)
     return SILC_SKE_STATUS_OUT_OF_MEMORY;
-  silc_buffer_pull_tail(buf, SILC_BUFFER_END(buf));
 
   /* Encode the payload */
   ret = silc_buffer_format(buf,
@@ -135,7 +133,6 @@ silc_ske_payload_start_decode(SilcSKE ske,
   }
 
   if (tmp != 0) {
-    SILC_LOG_DEBUG(("Bad reserved field"));
     SILC_LOG_ERROR(("Bad RESERVED field in KE Start Payload"));
     status = SILC_SKE_STATUS_BAD_RESERVED_FIELD;
     goto err;
@@ -215,11 +212,10 @@ SilcSKEStatus silc_ske_payload_ke_encode(SilcSKE ske,
 
   /* Allocate channel payload buffer. The length of the buffer
      is 4 + public key + 2 + x + 2 + signature. */
-  buf = silc_buffer_alloc(4 + payload->pk_len + 2 + x_len + 
-                         2 + payload->sign_len);
+  buf = silc_buffer_alloc_size(4 + payload->pk_len + 2 + x_len + 
+                              2 + payload->sign_len);
   if (!buf)
     return SILC_SKE_STATUS_OUT_OF_MEMORY;
-  silc_buffer_pull_tail(buf, SILC_BUFFER_END(buf));
 
   /* Encode the payload */
   ret = silc_buffer_format(buf, 
index 9388324c54edd1eda226cdc27ba6a65711e0f8c7..2fd4e0107ea646bea7f2fe87dabc7d29830a80a6 100644 (file)
@@ -111,6 +111,8 @@ void silc_ske_free(SilcSKE ske)
     }
     silc_free(ske->hash);
     silc_free(ske->callbacks);
+
+    memset(ske, 'F', sizeof(*ske));
     silc_free(ske);
   }
 }
@@ -1185,7 +1187,7 @@ silc_ske_assemble_security_properties(SilcSKE ske,
   /* Set random cookie */
   rp->cookie = silc_calloc(SILC_SKE_COOKIE_LEN, sizeof(*rp->cookie));
   for (i = 0; i < SILC_SKE_COOKIE_LEN; i++)
-    rp->cookie[i] = silc_rng_get_byte(ske->rng);
+    rp->cookie[i] = silc_rng_get_byte_fast(ske->rng);
   rp->cookie_len = SILC_SKE_COOKIE_LEN;
 
   /* Put version */
@@ -1214,8 +1216,8 @@ silc_ske_assemble_security_properties(SilcSKE ske,
 
   /* XXX */
   /* Get supported compression algorithms */
-  rp->comp_alg_list = strdup("");
-  rp->comp_alg_len = 0;
+  rp->comp_alg_list = strdup("none");
+  rp->comp_alg_len = strlen("none");
 
   rp->len = 1 + 1 + 2 + SILC_SKE_COOKIE_LEN + 
     2 + rp->version_len +
@@ -1541,9 +1543,8 @@ silc_ske_select_security_properties(SilcSKE ske,
     payload->hmac_alg_list = strdup(rp->hmac_alg_list);
   }
 
-#if 0
   /* Get supported compression algorithms */
-  cp = rp->hash_alg_list;
+  cp = rp->comp_alg_list;
   if (cp && strchr(cp, ',')) {
     while(cp) {
       char *item;
@@ -1552,15 +1553,23 @@ silc_ske_select_security_properties(SilcSKE ske,
       item = silc_calloc(len + 1, sizeof(char));
       memcpy(item, cp, len);
 
-      SILC_LOG_DEBUG(("Proposed hash alg `%s'", item));
+      SILC_LOG_DEBUG(("Proposed Compression `%s'", item));
 
-      if (silc_hash_is_supported(item) == TRUE) {
-       SILC_LOG_DEBUG(("Found hash alg `%s'", item));
-
-       payload->hash_alg_len = len;
-       payload->hash_alg_list = item;
+#if 1
+      if (!strcmp(item, "none")) {
+       SILC_LOG_DEBUG(("Found Compression `%s'", item));
+       payload->comp_alg_len = len;
+       payload->comp_alg_list = item;
+       break;
+      }
+#else
+      if (silc_hmac_is_supported(item) == TRUE) {
+       SILC_LOG_DEBUG(("Found Compression `%s'", item));
+       payload->comp_alg_len = len;
+       payload->comp_alg_list = item;
        break;
       }
+#endif
 
       cp += len;
       if (strlen(cp) == 0)
@@ -1571,20 +1580,7 @@ silc_ske_select_security_properties(SilcSKE ske,
       if (item)
        silc_free(item);
     }
-
-    if (!payload->hash_alg_len && !payload->hash_alg_list) {
-      SILC_LOG_DEBUG(("Could not find supported hash alg"));
-      silc_ske_abort(ske, SILC_SKE_STATUS_UNKNOWN_HASH_FUNCTION);
-      silc_free(payload->ke_grp_list);
-      silc_free(payload->pkcs_alg_list);
-      silc_free(payload->enc_alg_list);
-      silc_free(payload);
-      return;
-    }
-  } else {
-
   }
-#endif
 
   payload->len = 1 + 1 + 2 + SILC_SKE_COOKIE_LEN + 
     2 + payload->version_len + 
@@ -1604,16 +1600,22 @@ static SilcSKEStatus silc_ske_create_rnd(SilcSKE ske, SilcMPInt *n,
 {
   SilcSKEStatus status = SILC_SKE_STATUS_OK;
   unsigned char *string;
+  SilcUInt32 l;
+
+  if (!len)
+    return SILC_SKE_STATUS_ERROR;
 
   SILC_LOG_DEBUG(("Creating random number"));
 
+  l = ((len - 1) / 8);
+
   /* Get the random number as string */
-  string = silc_rng_get_rn_data(ske->rng, ((len - 1) / 8));
+  string = silc_rng_get_rn_data(ske->rng, l);
   if (!string)
     return SILC_SKE_STATUS_OUT_OF_MEMORY;
 
   /* Decode the string into a MP integer */
-  silc_mp_bin2mp(string, ((len - 1) / 8), rnd);
+  silc_mp_bin2mp(string, l, rnd);
   silc_mp_mod_2exp(rnd, rnd, len);
 
   /* Checks */
@@ -1622,7 +1624,7 @@ static SilcSKEStatus silc_ske_create_rnd(SilcSKE ske, SilcMPInt *n,
   if (silc_mp_cmp(rnd, n) >= 0)
     status = SILC_SKE_STATUS_ERROR;
 
-  memset(string, 'F', (len / 8));
+  memset(string, 'F', l);
   silc_free(string);
 
   return status;
index c323a631fca987bd000f61cb80ef75e9473c8292..4fffb7c34d87b7144f9007c921453c97b9e2dfe0 100644 (file)
 
 #include "silcincludes.h"
 
-/* Macro to check whether there is enough free space to add the
+/* Macros to check whether there is enough free space to add the
    required amount of data. For unformatting this means that there must
    be the data that is to be extracted. */
-#define MY_HAS_SPACE(__x__, __req__)           \
+#define FORMAT_HAS_SPACE(__x__, __req__)       \
   do {                                         \
     if (__req__ > (__x__)->len)                        \
       goto fail;                               \
   } while(0)
+#define UNFORMAT_HAS_SPACE(__x__, __req__)     \
+  do {                                         \
+    if (__req__ > (__x__)->len)                        \
+      goto fail;                               \
+    if ((__req__ + 1) <= 0)                    \
+      goto fail;                               \
+  } while(0)
 
 /* Formats the arguments sent and puts them into the buffer sent as
    argument. The buffer must be initialized beforehand and it must have
@@ -63,7 +70,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
     case SILC_BUFFER_PARAM_SI8_CHAR:
       {
        char x = (char)va_arg(ap, int);
-       MY_HAS_SPACE(dst, 1);
+       FORMAT_HAS_SPACE(dst, 1);
        silc_buffer_put(dst, &x, 1);
        silc_buffer_pull(dst, 1);
        break;
@@ -71,7 +78,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
     case SILC_BUFFER_PARAM_UI8_CHAR:
       {
        unsigned char x = (unsigned char)va_arg(ap, int);
-       MY_HAS_SPACE(dst, 1);
+       FORMAT_HAS_SPACE(dst, 1);
        silc_buffer_put(dst, &x, 1);
        silc_buffer_pull(dst, 1);
        break;
@@ -80,7 +87,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[2];
        SilcInt16 x = (SilcInt16)va_arg(ap, int);
-       MY_HAS_SPACE(dst, 2);
+       FORMAT_HAS_SPACE(dst, 2);
        SILC_PUT16_MSB(x, xf);
        silc_buffer_put(dst, xf, 2);
        silc_buffer_pull(dst, 2);
@@ -90,7 +97,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[2];
        SilcUInt16 x = (SilcUInt16)va_arg(ap, int);
-       MY_HAS_SPACE(dst, 2);
+       FORMAT_HAS_SPACE(dst, 2);
        SILC_PUT16_MSB(x, xf);
        silc_buffer_put(dst, xf, 2);
        silc_buffer_pull(dst, 2);
@@ -100,7 +107,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[4];
        SilcInt32 x = va_arg(ap, SilcInt32);
-       MY_HAS_SPACE(dst, 4);
+       FORMAT_HAS_SPACE(dst, 4);
        SILC_PUT32_MSB(x, xf);
        silc_buffer_put(dst, xf, 4);
        silc_buffer_pull(dst, 4);
@@ -110,7 +117,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[4];
        SilcUInt32 x = va_arg(ap, SilcUInt32);
-       MY_HAS_SPACE(dst, 4);
+       FORMAT_HAS_SPACE(dst, 4);
        SILC_PUT32_MSB(x, xf);
        silc_buffer_put(dst, xf, 4);
        silc_buffer_pull(dst, 4);
@@ -120,7 +127,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[8];
        SilcInt64 x = va_arg(ap, SilcInt64);
-       MY_HAS_SPACE(dst, sizeof(SilcInt64));
+       FORMAT_HAS_SPACE(dst, sizeof(SilcInt64));
        SILC_PUT64_MSB(x, xf);
        silc_buffer_put(dst, xf, sizeof(SilcInt64));
        silc_buffer_pull(dst, sizeof(SilcInt64));
@@ -130,7 +137,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[8];
        SilcUInt64 x = va_arg(ap, SilcUInt64);
-       MY_HAS_SPACE(dst, sizeof(SilcUInt64));
+       FORMAT_HAS_SPACE(dst, sizeof(SilcUInt64));
        SILC_PUT64_MSB(x, xf);
        silc_buffer_put(dst, xf, sizeof(SilcUInt64));
        silc_buffer_pull(dst, sizeof(SilcUInt64));
@@ -145,7 +152,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char *x = va_arg(ap, unsigned char *);
        SilcUInt32 tmp_len = strlen(x);
-       MY_HAS_SPACE(dst, tmp_len);
+       FORMAT_HAS_SPACE(dst, tmp_len);
        silc_buffer_put(dst, x, tmp_len);
        silc_buffer_pull(dst, tmp_len);
        break;
@@ -162,7 +169,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
        unsigned char *x = va_arg(ap, unsigned char *);
        SilcUInt32 len = va_arg(ap, SilcUInt32);
        if (x && len) {
-         MY_HAS_SPACE(dst, len);
+         FORMAT_HAS_SPACE(dst, len);
          silc_buffer_put(dst, x, len);
          silc_buffer_pull(dst, len);
        }
@@ -223,7 +230,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_SI8_CHAR:
       {
        char *x = va_arg(ap, char *);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        if (x)
          *x = src->data[0];
        silc_buffer_pull(src, 1);
@@ -232,7 +239,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_UI8_CHAR:
       {
        unsigned char *x = va_arg(ap, unsigned char *);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        if (x)
          *x = src->data[0];
        silc_buffer_pull(src, 1);
@@ -241,7 +248,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_SI16_SHORT:
       {
        SilcInt16 *x = va_arg(ap, SilcInt16 *);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        if (x)
          SILC_GET16_MSB(*x, src->data);
        silc_buffer_pull(src, 2);
@@ -250,7 +257,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_UI16_SHORT:
       {
        SilcUInt16 *x = va_arg(ap, SilcUInt16 *);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        if (x)
          SILC_GET16_MSB(*x, src->data);
        silc_buffer_pull(src, 2);
@@ -259,7 +266,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_SI32_INT:
       {
        SilcInt32 *x = va_arg(ap, SilcInt32 *);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        if (x)
          SILC_GET32_MSB(*x, src->data);
        silc_buffer_pull(src, 4);
@@ -268,7 +275,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_UI32_INT:
       {
        SilcUInt32 *x = va_arg(ap, SilcUInt32 *);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        if (x)
          SILC_GET32_MSB(*x, src->data);
        silc_buffer_pull(src, 4);
@@ -277,7 +284,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_SI64_INT:
       {
        SilcInt64 *x = va_arg(ap, SilcInt64 *);
-       MY_HAS_SPACE(src, sizeof(SilcInt64));
+       UNFORMAT_HAS_SPACE(src, sizeof(SilcInt64));
        if (x)
          SILC_GET64_MSB(*x, src->data);
        silc_buffer_pull(src, sizeof(SilcInt64));
@@ -286,7 +293,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_UI64_INT:
       {
        SilcUInt64 *x = va_arg(ap, SilcUInt64 *);
-       MY_HAS_SPACE(src, sizeof(SilcUInt64));
+       UNFORMAT_HAS_SPACE(src, sizeof(SilcUInt64));
        if (x)
          SILC_GET64_MSB(*x, src->data);
        silc_buffer_pull(src, sizeof(SilcUInt64));
@@ -296,10 +303,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt8 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        len2 = (SilcUInt8)src->data[0];
        silc_buffer_pull(src, 1);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x)
          *x = src->data;
        silc_buffer_pull(src, len2);
@@ -309,10 +316,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt16 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        SILC_GET16_MSB(len2, src->data);
        silc_buffer_pull(src, 2);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x)
          *x = src->data;
        silc_buffer_pull(src, len2);
@@ -322,10 +329,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt8 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        len2 = (SilcUInt8)src->data[0];
        silc_buffer_pull(src, 1);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x && len2) {
          *x = silc_calloc(len2 + 1, sizeof(unsigned char));
          memcpy(*x, src->data, len2);
@@ -337,10 +344,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt16 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        SILC_GET16_MSB(len2, src->data);
        silc_buffer_pull(src, 2);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x && len2) {
          *x = silc_calloc(len2 + 1, sizeof(unsigned char));
          memcpy(*x, src->data, len2);
@@ -352,10 +359,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt32 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        SILC_GET32_MSB(len2, src->data);
        silc_buffer_pull(src, 4);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x)
          *x = src->data;
        silc_buffer_pull(src, len2);
@@ -365,10 +372,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt32 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        SILC_GET32_MSB(len2, src->data);
        silc_buffer_pull(src, 4);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x && len2) {
          *x = silc_calloc(len2 + 1, sizeof(unsigned char));
          memcpy(*x, src->data, len2);
@@ -381,10 +388,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt8 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt8 *len = va_arg(ap, SilcUInt8 *);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        len2 = (SilcUInt8)src->data[0];
        silc_buffer_pull(src, 1);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x)
@@ -397,10 +404,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt16 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt16 *len = va_arg(ap, SilcUInt16 *);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        SILC_GET16_MSB(len2, src->data);
        silc_buffer_pull(src, 2);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x)
@@ -413,10 +420,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt8 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt8 *len = va_arg(ap, SilcUInt8 *);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        len2 = (SilcUInt8)src->data[0];
        silc_buffer_pull(src, 1);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x && len2) {
@@ -431,10 +438,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt16 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt16 *len = va_arg(ap, SilcUInt16 *);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        SILC_GET16_MSB(len2, src->data);
        silc_buffer_pull(src, 2);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x && len2) {
@@ -449,10 +456,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt32 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt32 *len = va_arg(ap, SilcUInt32 *);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        SILC_GET32_MSB(len2, src->data);
        silc_buffer_pull(src, 4);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x)
@@ -464,7 +471,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt32 len = va_arg(ap, SilcUInt32);
-       MY_HAS_SPACE(src, len);
+       UNFORMAT_HAS_SPACE(src, len);
        if (len && x)
          *x = src->data;
        silc_buffer_pull(src, len);
@@ -474,7 +481,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt32 len = va_arg(ap, SilcUInt32);
-       MY_HAS_SPACE(src, len);
+       UNFORMAT_HAS_SPACE(src, len);
        if (len && x) {
          *x = silc_calloc(len + 1, sizeof(unsigned char));
          memcpy(*x, src->data, len);
index f179dc1d03df1fa9c8d8aec63a99afe9a589e1c7..1f3e4699fdf79d20891961d4463f4b507dd69a73 100644 (file)
@@ -41,13 +41,14 @@ typedef struct SilcConfigOptionStruct {
 
 /* unique for each config file (and included ones) */
 struct SilcConfigFileObject {
-  char *filename; /* the original filename opened */
-  int level;   /* parsing level, how many nested silc_config_main we have */
-  char *base;  /* this is a fixed pointer to the base location */
-  char *p;     /* the Parser poitner */
+  char *filename;      /* the original filename opened */
+  int level;           /* parsing level, how many nested
+                          silc_config_main we have */
+  char *base;          /* this is a fixed pointer to the base location */
+  char *p;             /* the Parser poitner */
   SilcUInt32 len;      /* fixed length of the whole file */
   SilcUInt32 line;     /* current parsing line, strictly linked to p */
-  bool included; /* wether this file is main or included */
+  bool included;       /* wether this file is main or included */
 };
 
 /* We need the entity to base our block-style parsing on */
@@ -58,23 +59,23 @@ struct SilcConfigEntityObject {
 
 /* access error descriptions only with silc_config_strerror() */
 static char *errorstrs[] = {
-  "-OK",                                       /* SILC_CONFIG_OK */
-  "-SILENT",                                   /* SILC_CONFIG_ESILENT */
-  "-PRINTLINE",                                        /* SILC_CONFIG_EPRINTLINE */
-  "Invalid syntax",                            /* SILC_CONFIG_EGENERIC */
-  "Internal error! Please report this bug",    /* SILC_CONFIG_EINTERNAL */
-  "Can't open specified file",                 /* SILC_CONFIG_ECANTOPEN */
-  "Expected open-brace '{'",                   /* SILC_CONFIG_EOPENBRACE */
-  "Missing close-brace '}'",                   /* SILC_CONFIG_ECLOSEBRACE */
-  "Invalid data type",                         /* SILC_CONFIG_ETYPE */
-  "Unknown option",                            /* SILC_CONFIG_EBADOPTION */
-  "Invalid text",                              /* SILC_CONFIG_EINVALIDTEXT */
-  "Double option specification",               /* SILC_CONFIG_EDOUBLE */
-  "Expected data but not found",               /* SILC_CONFIG_EEXPECTED */
-  "Expected '='",                              /* SILC_CONFIG_EEXPECTEDEQUAL */
-  "Unexpected data",                           /* SILC_CONFIG_EUNEXPECTED */
-  "Missing mandatory fields",                  /* SILC_CONFIG_EMISSFIELDS */
-  "Missing ';'",                               /* SILC_CONFIG_EMISSCOLON */
+  "-OK",                                     /* SILC_CONFIG_OK */
+  "-SILENT",                                 /* SILC_CONFIG_ESILENT */
+  "-PRINTLINE",                                      /* SILC_CONFIG_EPRINTLINE */
+  "Invalid syntax",                          /* SILC_CONFIG_EGENERIC */
+  "Internal error! Please report this bug",   /* SILC_CONFIG_EINTERNAL */
+  "Can't open specified file",               /* SILC_CONFIG_ECANTOPEN */
+  "Expected open-brace '{'",                 /* SILC_CONFIG_EOPENBRACE */
+  "Missing close-brace '}'",                 /* SILC_CONFIG_ECLOSEBRACE */
+  "Invalid data type",                       /* SILC_CONFIG_ETYPE */
+  "Unknown option",                          /* SILC_CONFIG_EBADOPTION */
+  "Invalid text",                            /* SILC_CONFIG_EINVALIDTEXT */
+  "Double option specification",             /* SILC_CONFIG_EDOUBLE */
+  "Expected data but not found",             /* SILC_CONFIG_EEXPECTED */
+  "Expected '='",                            /* SILC_CONFIG_EEXPECTEDEQUAL */
+  "Unexpected data",                         /* SILC_CONFIG_EUNEXPECTED */
+  "Missing mandatory fields",                /* SILC_CONFIG_EMISSFIELDS */
+  "Missing ';'",                             /* SILC_CONFIG_EMISSCOLON */
 };
 
 /* return string describing SilcConfig's error code */
@@ -321,7 +322,7 @@ char *silc_config_read_line(SilcConfigFile *file, SilcUInt32 line)
 {
   register char *p;
   int len;
-  char *ret, *endbuf;
+  char *ret = NULL, *endbuf;
 
   if (!file || (line <= 0))
     return NULL;
@@ -336,7 +337,8 @@ char *silc_config_read_line(SilcConfigFile *file, SilcUInt32 line)
  found:
   if ((endbuf = strchr(p, '\n'))) {
     len = endbuf - p;
-    ret = silc_memdup(p, len);
+    if (len > 0)
+      ret = silc_memdup(p, len);
   } else {
     ret = silc_memdup(p, strlen(p));
   }
@@ -383,8 +385,9 @@ bool silc_config_register(SilcConfigEntity ent, const char *name,
                          const SilcConfigTable *subtable, void *context)
 {
   SilcConfigOption *newopt;
-  SILC_CONFIG_DEBUG(("Register new option=\"%s\" type=%u cb=0x%08x context=0x%08x",
-               name, type, (SilcUInt32) cb, (SilcUInt32) context));
+  SILC_CONFIG_DEBUG(("Register new option=\"%s\" "
+                    "type=%u cb=0x%08x context=0x%08x",
+                    name, type, (SilcUInt32) cb, (SilcUInt32) context));
 
   /* if we are registering a block, make sure there is a specified sub-table */
   if (!ent || !name || ((type == SILC_CONFIG_ARG_BLOCK) && !subtable))
@@ -469,7 +472,8 @@ static int silc_config_main_internal(SilcConfigEntity ent)
 
     /* obtain the keyword */
     my_next_token(file, buf);
-    SILC_CONFIG_DEBUG(("Looking up keyword=\"%s\" [line=%lu]", buf, file->line));
+    SILC_CONFIG_DEBUG(("Looking up keyword=\"%s\" [line=%lu]",
+                      buf, file->line));
 
     /* handle special directive */
     if (!strcasecmp(buf, "include")) {
index 6b342b9f26414a4b0135a23d21b862582d989764..e0f658b08f52807e42fa93107a14f107155bbf59 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silcschedule.c
+  silcschedule.c 
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1998 - 2001 Pekka Riikonen
+  Copyright (C) 1998 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -343,8 +342,8 @@ void silc_schedule_stop(SilcSchedule schedule)
 static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
 {
   SilcTask task;
-  int i, last_fd = schedule->last_fd;
-  SilcUInt32 fd;
+  int i;
+  SilcUInt32 fd, last_fd = schedule->last_fd;
 
   for (i = 0; i <= last_fd; i++) {
     if (schedule->fd_list[i].events == 0)