From: Pekka Riikonen Date: Sun, 29 Dec 2002 21:27:37 +0000 (+0000) Subject: int -> SilcUInt32 changes. X-Git-Tag: silc.client.0.9.11~9 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=7c14d7a478921ddcee0c19074530389fb426b4dc;p=silc.git int -> SilcUInt32 changes. --- diff --git a/apps/silcd/serverconfig.c b/apps/silcd/serverconfig.c index c3d3a7f3..911caff0 100644 --- a/apps/silcd/serverconfig.c +++ b/apps/silcd/serverconfig.c @@ -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; diff --git a/lib/silccore/silcargument.c b/lib/silccore/silcargument.c index c58a1c98..d492ed74 100644 --- a/lib/silccore/silcargument.c +++ b/lib/silccore/silcargument.c @@ -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); diff --git a/lib/silccore/silcattrs.c b/lib/silccore/silcattrs.c index fee2c395..2ba0117b 100644 --- a/lib/silccore/silcattrs.c +++ b/lib/silccore/silcattrs.c @@ -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); diff --git a/lib/silccore/silcchannel.c b/lib/silccore/silcchannel.c index 2c1b7155..5c83bbb4 100644 --- a/lib/silccore/silcchannel.c +++ b/lib/silccore/silcchannel.c @@ -1,24 +1,22 @@ /* - silcchannel.c + silcchannel.c - Author: Pekka Riikonen + Author: Pekka Riikonen - 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")); diff --git a/lib/silccore/silccommand.c b/lib/silccore/silccommand.c index d8470570..a16dfc6f 100644 --- a/lib/silccore/silccommand.c +++ b/lib/silccore/silccommand.c @@ -1,16 +1,15 @@ /* - silccommand.c + silccommand.c Author: Pekka Riikonen - 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); } diff --git a/lib/silccore/silcidcache.c b/lib/silccore/silcidcache.c index 19adb9ff..3d6904e7 100644 --- a/lib/silccore/silcidcache.c +++ b/lib/silccore/silcidcache.c @@ -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; } diff --git a/lib/silccore/silcnotify.c b/lib/silccore/silcnotify.c index 20a42e9e..f8a6389a 100644 --- a/lib/silccore/silcnotify.c +++ b/lib/silccore/silcnotify.c @@ -1,16 +1,15 @@ /* - silcnotify.c + silcnotify.c - Author: Pekka Riikonen + Author: Pekka Riikonen - 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); diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index 6643945b..7bac3681 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -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")); diff --git a/lib/silccore/silcpacket.h b/lib/silccore/silcpacket.h index 0e15ae43..b2c9dd27 100644 --- a/lib/silccore/silcpacket.h +++ b/lib/silccore/silcpacket.h @@ -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) /***/ diff --git a/lib/silccore/tests/test_silcargument.c b/lib/silccore/tests/test_silcargument.c index 58f84659..0b36d326 100644 --- a/lib/silccore/tests/test_silcargument.c +++ b/lib/silccore/tests/test_silcargument.c @@ -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); diff --git a/lib/silcsftp/sftp_util.c b/lib/silcsftp/sftp_util.c index 2e982d6d..dc2f5cff 100644 --- a/lib/silcsftp/sftp_util.c +++ b/lib/silcsftp/sftp_util.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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), diff --git a/lib/silcske/payload.c b/lib/silcske/payload.c index 99457a80..d7fb301d 100644 --- a/lib/silcske/payload.c +++ b/lib/silcske/payload.c @@ -1,16 +1,15 @@ /* - payload.c + payload.c Author: Pekka Riikonen - 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, diff --git a/lib/silcske/silcske.c b/lib/silcske/silcske.c index 9388324c..2fd4e010 100644 --- a/lib/silcske/silcske.c +++ b/lib/silcske/silcske.c @@ -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; diff --git a/lib/silcutil/silcbuffmt.c b/lib/silcutil/silcbuffmt.c index c323a631..4fffb7c3 100644 --- a/lib/silcutil/silcbuffmt.c +++ b/lib/silcutil/silcbuffmt.c @@ -21,14 +21,21 @@ #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); diff --git a/lib/silcutil/silcconfig.c b/lib/silcutil/silcconfig.c index f179dc1d..1f3e4699 100644 --- a/lib/silcutil/silcconfig.c +++ b/lib/silcutil/silcconfig.c @@ -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")) { diff --git a/lib/silcutil/silcschedule.c b/lib/silcutil/silcschedule.c index 6b342b9f..e0f658b0 100644 --- a/lib/silcutil/silcschedule.c +++ b/lib/silcutil/silcschedule.c @@ -1,16 +1,15 @@ /* - silcschedule.c + silcschedule.c Author: Pekka Riikonen - 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)