From: Pekka Riikonen Date: Thu, 8 Jan 2009 09:20:01 +0000 (+0200) Subject: Merge branch 'topic/detach-fixes' of git://valera-ext.nynaeve.net/silc into silc... X-Git-Tag: silc.toolkit.1.1.9~4 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=e88214b3fedc6e80fa8d1833df3ac40af31a75eb;hp=6e596af78adee828595e00a0988625453f9ecbc9;p=silc.git Merge branch 'topic/detach-fixes' of git://valera-ext.nynaeve.net/silc into silc.1.1.branch --- diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index 16feddc7..cfefe327 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -1677,7 +1677,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn, if (idle && nickname) { memset(buf, 0, sizeof(buf)); - snprintf(buf, sizeof(buf) - 1, "%lu %s", + snprintf(buf, sizeof(buf) - 1, "%u %s", idle > 60 ? (idle / 60) : idle, idle > 60 ? "minutes" : "seconds"); diff --git a/apps/silc/clientutil.c b/apps/silc/clientutil.c index 71b628bc..6a41a7c9 100644 --- a/apps/silc/clientutil.c +++ b/apps/silc/clientutil.c @@ -113,7 +113,7 @@ int silc_get_number_of_emails() if (!tl) { fprintf(stderr, "Couldn't open mail file (%s).\n", filename); } else { - while((fscanf(tl, "%s", data)) != EOF) { + while((fscanf(tl, "%1023s", data)) != EOF) { if(!strcmp(data, "From:")) num++; } diff --git a/apps/silcd/server.c b/apps/silcd/server.c index ab1d7374..5120382a 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -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 */ @@ -5025,7 +5033,7 @@ void silc_server_save_users_on_channel(SilcServer server, } if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED)) { - SILC_LOG_ERROR(("Attempting to add unregistered client to channel ", + SILC_LOG_ERROR(("Attempting to add unregistered client to channel " "%s", channel->channel_name)); continue; } diff --git a/apps/silcd/server_internal.h b/apps/silcd/server_internal.h index fd948ffe..09257e66 100644 --- a/apps/silcd/server_internal.h +++ b/apps/silcd/server_internal.h @@ -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)) { \ diff --git a/apps/silcd/serverconfig.c b/apps/silcd/serverconfig.c index 30d76af3..a2c58923 100644 --- a/apps/silcd/serverconfig.c +++ b/apps/silcd/serverconfig.c @@ -1542,7 +1542,7 @@ SilcServerConfig silc_server_config_alloc(const char *filename, silc_config_strerror(ret))); linebuf = silc_config_read_line(file, line); if (linebuf) { - SILC_SERVER_LOG_ERROR((" file %s line %lu: %s\n", filename, + SILC_SERVER_LOG_ERROR((" file %s line %u: %s\n", filename, line, linebuf)); silc_free(linebuf); } diff --git a/apps/silcmap/silcmap_bitmap.c b/apps/silcmap/silcmap_bitmap.c index 6440f88d..b171f47b 100644 --- a/apps/silcmap/silcmap_bitmap.c +++ b/apps/silcmap/silcmap_bitmap.c @@ -52,7 +52,7 @@ bool silc_map_load_ppm(SilcMap map, const char *filename) } /* Read width and height */ - ret = sscanf(header, "%s %ld %ld %ld\n", type, + ret = sscanf(header, "%2s %ld %ld %ld\n", type, (unsigned long *)&map->width, (unsigned long *)&map->height, (unsigned long *)&map->maxcolor); diff --git a/lib/silcapputil/silcidcache.c b/lib/silcapputil/silcidcache.c index 831970d5..e2a7d8bb 100644 --- a/lib/silcapputil/silcidcache.c +++ b/lib/silcapputil/silcidcache.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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); diff --git a/lib/silcapputil/silcidcache.h b/lib/silcapputil/silcidcache.h index 7d8e1427..c3f48276 100644 --- a/lib/silcapputil/silcidcache.h +++ b/lib/silcapputil/silcidcache.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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 * diff --git a/lib/silcclient/client_entry.c b/lib/silcclient/client_entry.c index a7ec24ee..003f2fcf 100644 --- a/lib/silcclient/client_entry.c +++ b/lib/silcclient/client_entry.c @@ -1019,10 +1019,10 @@ SilcBool silc_client_del_client(SilcClient client, SilcClientConnection conn, if (!client_entry) return FALSE; - SILC_LOG_DEBUG(("Marking client entry %p deleted")); + SILC_LOG_DEBUG(("Marking client entry %p deleted", client_entry)); if (silc_atomic_sub_int32(&client_entry->internal.deleted, 1) != 0) { - SILC_LOG_DEBUG(("Client entry %p already marked deleted")); + SILC_LOG_DEBUG(("Client entry %p already marked deleted", client_entry)); return FALSE; } @@ -1722,10 +1722,10 @@ SilcBool silc_client_del_channel(SilcClient client, SilcClientConnection conn, if (!channel) return FALSE; - SILC_LOG_DEBUG(("Marking channel entry %p deleted")); + SILC_LOG_DEBUG(("Marking channel entry %p deleted", channel)); if (silc_atomic_sub_int32(&channel->internal.deleted, 1) != 0) { - SILC_LOG_DEBUG(("Channel entry %p already marked deleted")); + SILC_LOG_DEBUG(("Channel entry %p already marked deleted", channel)); return FALSE; } diff --git a/lib/silcclient/client_keyagr.c b/lib/silcclient/client_keyagr.c index 6a93b061..0d0ef8b4 100644 --- a/lib/silcclient/client_keyagr.c +++ b/lib/silcclient/client_keyagr.c @@ -368,7 +368,8 @@ void silc_client_abort_key_agreement(SilcClient client, ke = client_entry->internal.ke; - SILC_LOG_DEBUG(("Abort key agreement %p")); + SILC_LOG_DEBUG(("Abort key agreement ke %p for client %p on connection %p", + ke, client, conn)); ke->completion(client, conn, client_entry, SILC_KEY_AGREEMENT_ABORTED, NULL, ke->context); diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index 8b68c5ed..b6715675 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -1869,6 +1869,14 @@ static inline void silc_packet_receive_ctr_increment(SilcPacketStream stream, SILC_LOG_HEXDUMP(("Counter Block"), iv, 16); } +/* Return special packet's encrypted length */ + +static inline int silc_packet_special_len(unsigned char *data) +{ + return (((SilcUInt8)data[4] + (SilcUInt8)data[6] + + (SilcUInt8)data[7] + SILC_PACKET_HEADER_LEN)); +} + /* Decrypts SILC packet. Handles both normal and special packet decryption. Return 0 when packet is normal and 1 when it it special, -1 on error. */ @@ -1898,9 +1906,7 @@ static inline int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac, /* Padding length + src id len + dst id len + header length - 16 bytes already decrypted, gives the rest of the encrypted packet */ silc_buffer_push(buffer, block_len); - len = (((SilcUInt8)buffer->data[4] + (SilcUInt8)buffer->data[6] + - (SilcUInt8)buffer->data[7] + SILC_PACKET_HEADER_LEN) - - block_len); + len = silc_packet_special_len(buffer->data) - block_len; silc_buffer_pull(buffer, block_len); if (silc_unlikely(len > silc_buffer_len(buffer))) { @@ -2095,7 +2101,7 @@ static void silc_packet_read_process(SilcPacketStream stream) SilcCipher cipher; SilcHmac hmac; SilcPacket packet; - SilcUInt8 sid; + SilcUInt8 sid, flags, type; SilcUInt16 packetlen; SilcUInt32 paddedlen, mac_len, block_len, ivlen, psnlen; unsigned char tmp[SILC_PACKET_MIN_HEADER_LEN], *header; @@ -2197,6 +2203,39 @@ static void silc_packet_read_process(SilcPacketStream stream) /* Get packet length and full packet length with padding */ SILC_PACKET_LENGTH(header, packetlen, paddedlen); + /* Parse packet header */ + flags = (SilcPacketFlags)header[2]; + type = (SilcPacketType)header[3]; + + if (stream->sc->engine->local_is_router) { + if (type == SILC_PACKET_PRIVATE_MESSAGE && + (flags & SILC_PACKET_FLAG_PRIVMSG_KEY)) + normal = FALSE; + else if (type != SILC_PACKET_CHANNEL_MESSAGE || + (type == SILC_PACKET_CHANNEL_MESSAGE && + stream->is_router == TRUE)) + normal = TRUE; + } else { + if (type == SILC_PACKET_PRIVATE_MESSAGE && + (flags & SILC_PACKET_FLAG_PRIVMSG_KEY)) + normal = FALSE; + else if (type != SILC_PACKET_CHANNEL_MESSAGE) + normal = TRUE; + } + + /* Padding sanity checks */ + if (cipher && silc_cipher_get_mode(cipher) != SILC_CIPHER_MODE_CTR && + ((normal && paddedlen % block_len != 0) || + (!normal && silc_packet_special_len(header) % 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)", @@ -2241,6 +2280,8 @@ static void silc_packet_read_process(SilcPacketStream stream) goto out; } packet->stream = stream; + packet->flags = flags; + packet->type = type; /* Allocate more space to packet buffer, if needed */ if (silc_unlikely(silc_buffer_truelen(&packet->buffer) < paddedlen)) { @@ -2257,26 +2298,6 @@ static void silc_packet_read_process(SilcPacketStream stream) } } - /* Parse packet header */ - packet->flags = (SilcPacketFlags)header[2]; - packet->type = (SilcPacketType)header[3]; - - if (stream->sc->engine->local_is_router) { - if (packet->type == SILC_PACKET_PRIVATE_MESSAGE && - (packet->flags & SILC_PACKET_FLAG_PRIVMSG_KEY)) - normal = FALSE; - else if (packet->type != SILC_PACKET_CHANNEL_MESSAGE || - (packet->type == SILC_PACKET_CHANNEL_MESSAGE && - stream->is_router == TRUE)) - normal = TRUE; - } else { - if (packet->type == SILC_PACKET_PRIVATE_MESSAGE && - (packet->flags & SILC_PACKET_FLAG_PRIVMSG_KEY)) - normal = FALSE; - else if (packet->type != SILC_PACKET_CHANNEL_MESSAGE) - normal = TRUE; - } - SILC_LOG_HEXDUMP(("Incoming packet (%d) len %d", stream->receive_psn, paddedlen + ivlen + mac_len), inbuf->data, paddedlen + ivlen + mac_len); diff --git a/lib/silchttp/silchttpserver.c b/lib/silchttp/silchttpserver.c index cd94c407..e83d2f37 100644 --- a/lib/silchttp/silchttpserver.c +++ b/lib/silchttp/silchttpserver.c @@ -194,7 +194,7 @@ static SilcBool silc_http_server_parse(SilcHttpServer httpd, /* Check we have received all data */ cl = silc_mime_get_field(conn->curheaders, "Content-Length"); - if (cl && sscanf(cl, "%lu", (unsigned long *)&cll) == 1) { + if (cl && sscanf(cl, "%u", &cll) == 1) { if (data_len < cll) { /* More data to come */ silc_mime_free(conn->curheaders); diff --git a/lib/silcske/silcske.c b/lib/silcske/silcske.c index a4822e95..5cb7c91d 100644 --- a/lib/silcske/silcske.c +++ b/lib/silcske/silcske.c @@ -80,7 +80,7 @@ static SilcBool silc_ske_packet_send(SilcSKE ske, */ static void silc_ske_notify_failure(SilcSKE ske) { - SILC_LOG_DEBUG(("Notifying SKE %p owner of failure (failure_notified = %lu)", + SILC_LOG_DEBUG(("Notifying SKE %p owner of failure (failure_notified = %d)", ske, ske->failure_notified)); /* diff --git a/lib/silcskr/silcskr.c b/lib/silcskr/silcskr.c index 327c6124..c9b4be0d 100644 --- a/lib/silcskr/silcskr.c +++ b/lib/silcskr/silcskr.c @@ -748,7 +748,7 @@ void silc_skr_ref_public_key(SilcSKR skr, SilcSKRKey key) SilcSKRKeyInternal k = (SilcSKRKeyInternal)key; silc_mutex_lock(skr->lock); - SILC_LOG_DEBUG(("SKR key %p ref %d -> %d", k->refcnt, k->refcnt + 1)); + SILC_LOG_DEBUG(("SKR key %p ref %d -> %d", k, k->refcnt, k->refcnt + 1)); k->refcnt++; silc_mutex_unlock(skr->lock); } @@ -761,7 +761,7 @@ void silc_skr_unref_public_key(SilcSKR skr, SilcSKRKey key) silc_mutex_lock(skr->lock); - SILC_LOG_DEBUG(("SKR key %p ref %d -> %d", k->refcnt, k->refcnt - 1)); + SILC_LOG_DEBUG(("SKR key %p ref %d -> %d", k, k->refcnt, k->refcnt - 1)); k->refcnt--; if (k->refcnt == 0) { diff --git a/lib/silcutil/silcschedule.c b/lib/silcutil/silcschedule.c index 6c2f78ca..8d9738de 100644 --- a/lib/silcutil/silcschedule.c +++ b/lib/silcutil/silcschedule.c @@ -186,7 +186,7 @@ static void silc_schedule_select_timeout(SilcSchedule schedule) if (task) { schedule->timeout = curtime; schedule->has_timeout = TRUE; - SILC_LOG_DEBUG(("timeout: sec=%d, usec=%d", schedule->timeout.tv_sec, + SILC_LOG_DEBUG(("timeout: sec=%ld, usec=%ld", schedule->timeout.tv_sec, schedule->timeout.tv_usec)); } } @@ -290,7 +290,7 @@ void silc_schedule_stats(SilcSchedule schedule) { SilcTaskFd ftask; fprintf(stdout, "Schedule %p statistics:\n\n", schedule); - fprintf(stdout, "Num FD tasks : %lu (%lu bytes allocated)\n", + fprintf(stdout, "Num FD tasks : %u (%u bytes allocated)\n", silc_hash_table_count(schedule->fd_queue), sizeof(*ftask) * silc_hash_table_count(schedule->fd_queue)); fprintf(stdout, "Num Timeout tasks : %d (%d bytes allocated)\n", @@ -600,7 +600,7 @@ SilcTask silc_schedule_task_add(SilcSchedule schedule, SilcUInt32 fd, } } - SILC_LOG_DEBUG(("New timeout task %p: sec=%d, usec=%d", ttask, + SILC_LOG_DEBUG(("New timeout task %p: sec=%ld, usec=%ld", ttask, seconds, useconds)); /* Add task to correct spot so that the first task in the list has diff --git a/lib/silcutil/silcsocketstream.c b/lib/silcutil/silcsocketstream.c index af8f2c34..95b969d9 100644 --- a/lib/silcutil/silcsocketstream.c +++ b/lib/silcutil/silcsocketstream.c @@ -166,7 +166,7 @@ silc_socket_tcp_stream_create(SilcSocket sock, SilcBool lookup, return NULL; } - SILC_LOG_DEBUG(("Creating TCP socket stream %p, sock %lu", stream, sock)); + SILC_LOG_DEBUG(("Creating TCP socket stream %p, sock %lu", stream, (long unsigned) sock)); stream->ops = &silc_socket_stream_ops; stream->sock = sock; diff --git a/lib/silcutil/unix/silcunixschedule.c b/lib/silcutil/unix/silcunixschedule.c index 80e8fbf2..bcbe1203 100644 --- a/lib/silcutil/unix/silcunixschedule.c +++ b/lib/silcutil/unix/silcunixschedule.c @@ -274,7 +274,7 @@ SilcBool silc_schedule_internal_schedule_fd(SilcSchedule schedule, if (!internal) return TRUE; - SILC_LOG_DEBUG(("Scheduling fd %lu, mask %x", task->fd, event_mask)); + SILC_LOG_DEBUG(("Scheduling fd %u, mask %x", task->fd, event_mask)); memset(&event, 0, sizeof(event)); if (event_mask & SILC_TASK_READ) diff --git a/util/robodoc/Source/generator.c b/util/robodoc/Source/generator.c index 632c2990..2f9b9928 100644 --- a/util/robodoc/Source/generator.c +++ b/util/robodoc/Source/generator.c @@ -1403,7 +1403,7 @@ RB_HTML_Extra (FILE * dest_doc, int item_type, char *cur_char) if (strncmp ("http://", cur_char, strlen ("http://")) == 0) { - sscanf (cur_char, "%s", link); + sscanf (cur_char, "%1023s", link); RB_Say ("found link %s\n", link); res = (strlen (link) - 1); fprintf (dest_doc, "%s", link, link); @@ -1411,14 +1411,14 @@ RB_HTML_Extra (FILE * dest_doc, int item_type, char *cur_char) else if (strncmp ("href:", cur_char, strlen ("href:")) == 0) { /* handy in relative hyperlink paths, e.g. href:../../modulex/ */ - sscanf ((cur_char + strlen ("href:")), "%s", link); + sscanf ((cur_char + strlen ("href:")), "%1023s", link); RB_Say ("found link %s\n", link); res = (strlen (link) + strlen ("href:") - 1); fprintf (dest_doc, "%s", link, link); } else if (strncmp ("mailto:", cur_char, strlen ("mailto:")) == 0) { - sscanf ((cur_char + strlen ("mailto:")), "%s", link); + sscanf ((cur_char + strlen ("mailto:")), "%1023s", link); RB_Say ("found mail to %s\n", link); res = (strlen (link) + strlen ("mailto:") - 1); fprintf (dest_doc, "%s", link, link);