Merge branch 'topic/detach-fixes' of git://valera-ext.nynaeve.net/silc into silc...
authorPekka Riikonen <priikone@silcnet.org>
Sat, 13 Dec 2008 20:02:18 +0000 (22:02 +0200)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 13 Dec 2008 20:02:18 +0000 (22:02 +0200)
apps/silcd/server.c
apps/silcd/server_internal.h
lib/silcapputil/silcidcache.c
lib/silcapputil/silcidcache.h
lib/silccore/silcpacket.c

index 3d0623aca8c3aa2071299e4f0cd6b5f895f09158..2f97d79d837aaeee25893ad676f2f5cd1dab382d 100644 (file)
@@ -233,7 +233,10 @@ SILC_TASK_CALLBACK(silc_server_packet_error_timeout)
 
   if (server->router_conn && server->router_conn->sock == stream &&
       !server->router && server->standalone) {
+    if (idata->sconn && idata->sconn->callback)
+      (*idata->sconn->callback)(server, NULL, idata->sconn->callback_context);
     silc_server_create_connections(server);
+    silc_server_free_sock_user_data(server, stream, NULL);
   } else {
     /* If backup disconnected then mark that resuming will not be allowed */
      if (server->server_type == SILC_ROUTER && !server->backup_router &&
@@ -280,9 +283,14 @@ static void silc_server_packet_error(SilcPacketEngine engine,
   if (!silc_packet_stream_is_valid(stream))
     return;
 
+  /* In case we get here many times, register only one timeout */
+  silc_schedule_task_del_by_all(server->schedule, 0,
+                               silc_server_packet_error_timeout, stream);
+
+  /* Close connection with random timeout */
   silc_schedule_task_add_timeout(server->schedule,
                                 silc_server_packet_error_timeout, stream,
-                                silc_rng_get_byte(server->rng) % 5, 0);
+                                silc_rng_get_byte(server->rng) % 10, 0);
 }
 
 /* Packet stream callbacks */
index fd948ffe02c0158fb8f840fb5339d3a5657f5c8e..09257e66465a415a1d0f281a0b4e635348e8f3da 100644 (file)
@@ -166,29 +166,6 @@ typedef struct {
 #define SILC_IS_LOCAL(entry) \
   (((SilcIDListData)entry)->status & SILC_IDLIST_STATUS_LOCAL)
 
-/* Registers generic task for file descriptor for reading from network and
-   writing to network. As being generic task the actual task is allocated
-   only once and after that the same task applies to all registered fd's. */
-#define SILC_REGISTER_CONNECTION_FOR_IO(fd)            \
-do {                                                   \
-  silc_schedule_task_add(server->schedule, (fd),       \
-                        silc_server_packet_process,    \
-                        context, 0, 0,                 \
-                        SILC_TASK_GENERIC,             \
-                        SILC_TASK_PRI_NORMAL);         \
-} while(0)
-
-#define SILC_SET_CONNECTION_FOR_INPUT(s, fd)                           \
-do {                                                                   \
-  silc_schedule_set_listen_fd((s), (fd), SILC_TASK_READ, FALSE);       \
-} while(0)
-
-#define SILC_SET_CONNECTION_FOR_OUTPUT(s, fd)                               \
-do {                                                                        \
-  silc_schedule_set_listen_fd((s), (fd), (SILC_TASK_READ | SILC_TASK_WRITE), \
-                             FALSE);                                        \
-} while(0)
-
 #define SILC_OPER_STATS_UPDATE(c, type, mod)   \
 do {                                           \
   if ((c)->mode & (mod)) {                     \
index 831970d5dd940e3b298795f8863e2fbbe91b396a..e2a7d8bb874bc70d69f0cc58b4843079697d29ac 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2000 - 2007 Pekka Riikonen
+  Copyright (C) 2000 - 2008 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
@@ -55,7 +55,7 @@ static void silc_idcache_destructor(SilcIDCache cache,
                                    void *app_context)
 {
   if (cache->destructor)
-    cache->destructor(cache, entry, cache->destructor, app_context);
+    cache->destructor(cache, entry, cache->context, app_context);
 
   memset(entry, 'F', sizeof(*entry));
   silc_free(entry);
index 7d8e1427abfa2219e9b041185b6f475f6f6d3cba..c3f48276e10fbd14395bbba33ce5a30390b0b0f2 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2000 - 2007 Pekka Riikonen
+  Copyright (C) 2000 - 2008 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
@@ -185,7 +185,8 @@ SilcBool silc_idcache_del_by_id(SilcIDCache cache, void *id,
  *
  * SYNOPSIS
  *
- *    SilcBool silc_idcache_del_by_context(SilcIDCache cache, void *context);
+ *    SilcBool silc_idcache_del_by_context(SilcIDCache cache, void *context,
+ *                                         void *app_context);
  *
  * DESCRIPTION
  *
index 8b68c5ed17d00ddca0bb61f4456d9b0e33cc0d5b..767ec927a4712a9f24575571cea1a4a45de51724 100644 (file)
@@ -2197,6 +2197,18 @@ static void silc_packet_read_process(SilcPacketStream stream)
     /* Get packet length and full packet length with padding */
     SILC_PACKET_LENGTH(header, packetlen, paddedlen);
 
+    /* Padding sanity checks */
+    if (cipher && silc_cipher_get_mode(cipher) != SILC_CIPHER_MODE_CTR &&
+       (paddedlen % block_len) != 0) {
+      SILC_LOG_DEBUG(("Packet length %d not multiple by cipher block length",
+                     paddedlen));
+      silc_mutex_unlock(stream->lock);
+      SILC_PACKET_CALLBACK_ERROR(stream, SILC_PACKET_ERR_MALFORMED);
+      silc_mutex_lock(stream->lock);
+      memset(tmp, 0, sizeof(tmp));
+      goto out;
+    }
+
     if (silc_buffer_len(inbuf) < paddedlen + ivlen + mac_len) {
       SILC_LOG_DEBUG(("Received partial packet, waiting for the rest "
                      "(%d bytes)",