From 9dac7b6b7b035d55bdb9731795712ead92e11f76 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 7 Sep 2009 11:58:04 +0000 Subject: [PATCH] fixes --- src/core/core_api.c | 2 -- src/core/gnunet-service-core.c | 1 - src/datastore/gnunet-service-datastore.c | 1 - src/fs/fs_directory.c | 21 ++++++++++++--------- src/fs/fs_download.c | 4 ++-- src/fs/fs_search.c | 4 ++-- src/fs/fs_unindex.c | 4 ++-- src/fs/fs_uri.c | 1 - src/peerinfo/gnunet-service-peerinfo.c | 23 ++++++++++++++++++----- src/peerinfo/peerinfo_api.c | 3 +-- src/transport/gnunet-service-transport.c | 3 ++- src/transport/plugin_transport_tcp.c | 1 - src/util/configuration.c | 2 -- src/util/crypto_hash.c | 12 ++++-------- src/util/crypto_rsa.c | 5 ++--- src/util/disk.c | 1 - src/util/getopt_helpers.c | 9 ++++----- src/util/os_installation.c | 2 -- src/util/os_network.c | 4 +--- src/util/test_crypto_aes_weak.c | 1 - src/util/test_os_load.c | 2 +- src/util/test_scheduler.c | 13 ++++++------- 22 files changed, 57 insertions(+), 62 deletions(-) diff --git a/src/core/core_api.c b/src/core/core_api.c index ac958449b..6aca88640 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -272,11 +272,9 @@ static void timeout_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CORE_TransmitHandle *th = cls; - struct GNUNET_CORE_Handle *h; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission request timed out.\n"); - h = th->ch; th->timeout_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL)); GNUNET_CORE_notify_transmit_ready_cancel (th); diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 4012ac3a8..d950237cd 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -2918,7 +2918,6 @@ neighbour_quota_update (void *cls, account for possibility of new neighbours joining any time AND to convert to double... */ pref_rel = n->current_preference / (1.0 + preference_sum); - share = 0; distributable = 0; if (bandwidth_target_out > neighbour_count * MIN_BPM_PER_PEER) distributable = bandwidth_target_out - neighbour_count * MIN_BPM_PER_PEER; diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 87ae427e4..900c1a8c8 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -748,7 +748,6 @@ handle_release_reserve (void *cls, return; } prev = pos; - pos = next; } GNUNET_break (0); transmit_status (client, GNUNET_SYSERR, gettext_noop ("Could not find matching reservation")); diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c index d67c6e8ef..fa046b858 100644 --- a/src/fs/fs_directory.c +++ b/src/fs/fs_directory.c @@ -335,7 +335,8 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, fsize = 0; /* not given */ if (fsize > MAX_INLINE_SIZE) fsize = 0; /* too large */ - if (NULL != memchr (data, 0, fsize)) + if ( (NULL == data) || + (NULL != memchr (data, 0, fsize)) ) fsize = 0; /* must not have 0's in data! */ uris = GNUNET_FS_uri_to_string (uri); slen = strlen (uris) + 1; @@ -524,12 +525,11 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, sizes[i] = pos->len; pos = pos->next; } + block_align (size, + bld->count, + sizes, + perm); } - block_align (size, - bld->count, - sizes, - perm); - /* compute final size with alignment */ for (i = 0; i < bld->count; i++) { @@ -563,9 +563,12 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, sizes[i]); GNUNET_free (bes[i]); } - GNUNET_free (sizes); - GNUNET_free (perm); - GNUNET_free (bes); + if (bld->count > 0) + { + GNUNET_free (sizes); + GNUNET_free (perm); + GNUNET_free (bes); + } GNUNET_assert (off == size); GNUNET_CONTAINER_meta_data_destroy (bld->meta); GNUNET_free (bld); diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 77fbb1139..9ab4c5ce0 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -669,8 +669,8 @@ GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h, return NULL; // FIXME: add support for "loc" URIs! GNUNET_assert (GNUNET_FS_uri_test_chk (uri)); - if ( (dc->offset + dc->length < dc->offset) || - (dc->offset + dc->length > uri->data.chk.file_length) ) + if ( (offset + length < offset) || + (offset + length > uri->data.chk.file_length) ) { GNUNET_break (0); return NULL; diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index fd7dcf6d9..1a9fc699e 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -766,9 +766,9 @@ search_start (struct GNUNET_FS_Handle *h, _("Too many keywords specified for a single search.")); return NULL; } - client = GNUNET_CLIENT_connect (sc->h->sched, + client = GNUNET_CLIENT_connect (h->sched, "fs", - sc->h->cfg); + h->cfg); if (NULL == client) return NULL; sc = GNUNET_malloc (sizeof(struct GNUNET_FS_SearchContext)); diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index 03dae383f..977344b98 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c @@ -223,8 +223,8 @@ unindex_process (void *cls, } GNUNET_DATASTORE_remove (uc->dsh, query, - block_size, - block, + size, + data, &process_cont, uc, GNUNET_CONSTANTS_SERVICE_TIMEOUT); diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 61fb7d61d..4f4a82c2c 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c @@ -492,7 +492,6 @@ enc2bin (const char *input, void *data, size_t size) bits = 0; hbits = 0; len = 0; - pos = 0; for (pos = 0; pos < size; pos++) { while (hbits < 8) diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 3a6030fda..281779897 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c @@ -206,11 +206,24 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) { size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); hello = (const struct GNUNET_HELLO_Message *) buffer; - now = GNUNET_TIME_absolute_get (); - hello_clean = GNUNET_HELLO_iterate_addresses (hello, - GNUNET_YES, - &discard_expired, &now); - entry->hello = hello_clean; + if ( (size < sizeof (struct GNUNET_MessageHeader)) || + (size != ntohs((((const struct GNUNET_MessageHeader*) hello)->size))) || + (size != GNUNET_HELLO_size (hello)) ) + { + GNUNET_break (0); + if (0 != UNLINK (fn)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "unlink", + fn); + } + else + { + now = GNUNET_TIME_absolute_get (); + hello_clean = GNUNET_HELLO_iterate_addresses (hello, + GNUNET_YES, + &discard_expired, &now); + entry->hello = hello_clean; + } } GNUNET_free (fn); entry->next = hosts; diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index 28865edc6..57197798b 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c @@ -262,8 +262,8 @@ GNUNET_PEERINFO_for_all (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_CLIENT_Connection *client; struct ListAllPeersMessage *lapm; struct ListPeerMessage *lpm; - size_t hs; struct InfoContext *ihc; + size_t hs; client = GNUNET_CLIENT_connect (sched, "peerinfo", cfg); if (client == NULL) @@ -279,7 +279,6 @@ GNUNET_PEERINFO_for_all (const struct GNUNET_CONFIGURATION_Handle *cfg, ihc->callback = callback; ihc->callback_cls = callback_cls; ihc->timeout = GNUNET_TIME_relative_to_absolute (timeout); - hs = 0; if (peer == NULL) { lapm = (struct ListAllPeersMessage *) &ihc[1]; diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 3e696827f..09f87d444 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -2178,7 +2178,8 @@ plugin_env_receive (void *cls, } GNUNET_free (im); } - GNUNET_assert (NULL != service_context->neighbour); + GNUNET_assert ( (service_context == NULL) || + (NULL != service_context->neighbour) ); return service_context; } diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 17570254b..bfa17d275 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -1340,7 +1340,6 @@ update_quota (struct Session *session, int force) else { /* got more than acceptable */ - total_remaining = 0; session->last_received -= total_allowed; delta = 0; } diff --git a/src/util/configuration.c b/src/util/configuration.c index 0ce672dd9..8c32618e2 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -807,13 +807,11 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle char *end; char *match; char old; - int ret; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list)) return GNUNET_NO; match = escape_name (value); - ret = 0; pos = list; while (1) { diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index 45e599bcf..bc15113c6 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c @@ -214,10 +214,6 @@ sha512_transform (unsigned long long *state, const unsigned char *input) state[5] += f; state[6] += g; state[7] += h; - - /* erase our data */ - a = b = c = d = e = f = g = h = t1 = t2 = 0; - memset (W, 0, 80 * sizeof (unsigned long long)); } static void @@ -281,13 +277,13 @@ sha512_final (struct sha512_ctx *sctx, unsigned char *hash) static unsigned char padding[128] = { 0x80, }; unsigned int t; - unsigned long long t2; unsigned char bits[128]; - unsigned int index, pad_len; + unsigned int index; + unsigned int pad_len; + unsigned long long t2; int i, j; - index = pad_len = t = i = j = 0; - t2 = 0; + t = i = j = 0; /* Save number of bits */ t = sctx->count[0]; diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index f686c0359..edf1b2bdf 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -602,7 +602,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not aquire lock on file `%s' due to process %u: %s...\n"), - filename, fl.l_pid, STRERROR (errno)); + filename, fl.l_pid, STRERROR (ec)); } memset (&fl, 0, sizeof (struct flock)); fl.l_type = F_WRLCK; @@ -624,7 +624,6 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); - cnt = 0; if (0 != fcntl (fd, F_SETLK, &fl)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); @@ -659,7 +658,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not aquire lock on file `%s' due to process %u: %s...\n"), - filename, fl.l_pid, STRERROR (errno)); + filename, fl.l_pid, STRERROR (ec)); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("This may be ok if someone is currently generating a hostkey.\n")); diff --git a/src/util/disk.c b/src/util/disk.c index 3f46923f7..f6a4e7b90 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -1038,7 +1038,6 @@ GNUNET_DISK_file_open (const char *fn, int flags, ...) #ifndef MINGW mode = 0; - oflags = 0; if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE)) oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */ else if (flags & GNUNET_DISK_OPEN_READ) diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index 3aea5d102..a8a800a00 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c @@ -50,11 +50,11 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext const char *value) { const char *about = scls; - int slen; - int i; + size_t slen; + unsigned int i; int j; - int ml; - int p; + size_t ml; + size_t p; char *scp; const char *trans; const struct GNUNET_GETOPT_CommandLineOption *opt; @@ -62,7 +62,6 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); printf (_ ("Arguments mandatory for long options are also mandatory for short options.\n")); - slen = 0; i = 0; opt = ctx->allOptions; while (opt[i].description != NULL) diff --git a/src/util/os_installation.c b/src/util/os_installation.c index cc1d61c20..39b5174e3 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c @@ -213,14 +213,12 @@ get_path_from_PATH () char *end; char *buf; const char *p; - size_t size; p = getenv ("PATH"); if (p == NULL) return NULL; path = GNUNET_strdup (p); /* because we write on it */ buf = GNUNET_malloc (strlen (path) + 20); - size = strlen (path); pos = path; while (NULL != (end = strchr (pos, ':'))) diff --git a/src/util/os_network.c b/src/util/os_network.c index 4268772df..c872350c5 100644 --- a/src/util/os_network.c +++ b/src/util/os_network.c @@ -163,13 +163,11 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, #elif HAVE_GETIFADDRS && HAVE_FREEIFADDRS struct ifaddrs *ifa_first; + struct ifaddrs *ifa_ptr; socklen_t alen; if (getifaddrs (&ifa_first) == 0) { - struct ifaddrs *ifa_ptr; - - ifa_ptr = ifa_first; for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next) { if (ifa_ptr->ifa_name != NULL && diff --git a/src/util/test_crypto_aes_weak.c b/src/util/test_crypto_aes_weak.c index 2ce553a21..a694b6481 100644 --- a/src/util/test_crypto_aes_weak.c +++ b/src/util/test_crypto_aes_weak.c @@ -145,7 +145,6 @@ getWeakKeys () { printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n", number_of_runs, gcry_strerror (rc)); - rc = 0; continue; } diff --git a/src/util/test_os_load.c b/src/util/test_os_load.c index b46a3eb59..7165e7ef2 100644 --- a/src/util/test_os_load.c +++ b/src/util/test_os_load.c @@ -165,7 +165,7 @@ testdisk () } fprintf (stderr, "\n"); GNUNET_CONFIGURATION_destroy (cfg); - return 0; + return ret; } int diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index 0d5af1c0c..811389953 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c @@ -138,7 +138,6 @@ task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { int *ok = cls; GNUNET_SCHEDULER_TaskIdentifier t2; - GNUNET_SCHEDULER_TaskIdentifier t3; GNUNET_SCHEDULER_TaskIdentifier t4; GNUNET_assert (1 == *ok); @@ -154,12 +153,12 @@ task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_NO, GNUNET_SCHEDULER_PRIORITY_IDLE, t2, &task4, cls); - t3 = GNUNET_SCHEDULER_add_delayed (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - t2, - GNUNET_TIME_relative_get_zero (), - &task3, cls); + GNUNET_SCHEDULER_add_delayed (tc->sched, + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_DEFAULT, + t2, + GNUNET_TIME_relative_get_zero (), + &task3, cls); /* t4 will go first: lower prio, but prereq! */ GNUNET_SCHEDULER_add_after (tc->sched, GNUNET_NO, -- 2.25.1