Merge branch 'topic/serverlink-fixes' of git://valera-ext.nynaeve.net/silc into silc...
authorPekka Riikonen <priikone@silcnet.org>
Sat, 13 Dec 2008 16:18:20 +0000 (18:18 +0200)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 13 Dec 2008 16:18:20 +0000 (18:18 +0200)
Additional changes:

- Do not register packet error timeout multiple times
- Added padding length sanity checks to packet engine
- Removed old unused macros from silcd

1  2 
apps/silcd/server.c
apps/silcd/server_internal.h
lib/silccore/silcpacket.c

index dad1a44e268343eb98652e9c6366d526a42bb8a6,6cef2417d9c3ecd65a55f607390ff406e81c1ec9..777d724336699556b6d6d020eeb115566eb2e13d
@@@ -280,9 -283,9 +283,14 @@@ static void silc_server_packet_error(Si
    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,fd948ffe02c0158fb8f840fb5339d3a5657f5c8e..09257e66465a415a1d0f281a0b4e635348e8f3da
@@@ -166,29 -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 8b68c5ed17d00ddca0bb61f4456d9b0e33cc0d5b,8b68c5ed17d00ddca0bb61f4456d9b0e33cc0d5b..9a44f87c9f74948fce9202b1fcfc43bbcf6fba14
@@@ -2197,6 -2197,6 +2197,17 @@@ static void silc_packet_read_process(Si
      /* Get packet length and full packet length with padding */
      SILC_PACKET_LENGTH(header, packetlen, paddedlen);
  
++    /* Padding sanity checks */
++    if (cipher && (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)",