From 5bb4b33bf7cc18112ce1770e0012096e7bb9426b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 17 Jun 2010 21:56:21 +0000 Subject: [PATCH] fixes --- src/fs/fs_directory.c | 26 ++++++++++------ src/fs/fs_download.c | 28 +++++++++++------ src/fs/fs_search.c | 42 +++++++++++++++++--------- src/fs/gnunet-service-fs.c | 9 +++--- src/peerinfo/gnunet-service-peerinfo.c | 7 +++-- src/statistics/statistics_api.c | 11 ++++--- src/topology/gnunet-daemon-topology.c | 15 +++++---- src/transport/plugin_transport_tcp.c | 16 +++++++--- src/transport/plugin_transport_udp.c | 18 ++++++++--- src/util/os_priority.c | 5 +++ 10 files changed, 117 insertions(+), 60 deletions(-) diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c index 9c13073ab..fca2fc786 100644 --- a/src/fs/fs_directory.c +++ b/src/fs/fs_directory.c @@ -401,16 +401,24 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, GNUNET_assert (! GNUNET_FS_uri_test_ksk (uri)); if (NULL != data) - if (GNUNET_FS_uri_test_chk (uri)) - fsize = GNUNET_FS_uri_chk_get_file_size (uri); - else - { - curi = GNUNET_FS_uri_loc_get_uri (uri); - fsize = GNUNET_FS_uri_chk_get_file_size (curi); - GNUNET_FS_uri_destroy (curi); - } + { + GNUNET_assert (! GNUNET_FS_uri_test_sks (uri)); + if (GNUNET_FS_uri_test_chk (uri)) + { + fsize = GNUNET_FS_uri_chk_get_file_size (uri); + } + else + { + curi = GNUNET_FS_uri_loc_get_uri (uri); + GNUNET_assert (NULL != curi); + fsize = GNUNET_FS_uri_chk_get_file_size (curi); + GNUNET_FS_uri_destroy (curi); + } + } else - fsize = 0; /* not given */ + { + fsize = 0; /* not given */ + } if (fsize > MAX_INLINE_SIZE) fsize = 0; /* too large */ uris = GNUNET_FS_uri_to_string (uri); diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index b27aef8cd..057f57b53 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -330,10 +330,14 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, GNUNET_HashCode query; GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv); - GNUNET_CRYPTO_aes_encrypt (block, len, - &sk, - &iv, - enc); + if (-1 == GNUNET_CRYPTO_aes_encrypt (block, len, + &sk, + &iv, + enc)) + { + GNUNET_break (0); + goto do_download; + } GNUNET_CRYPTO_hash (enc, len, &query); if (0 == memcmp (&query, &chk->query, @@ -364,6 +368,7 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, return; } } + do_download: if (fh != NULL) GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); if (depth < dc->treedepth) @@ -915,11 +920,16 @@ process_result_with_request (void *cls, ppos = ppos->next; } GNUNET_CRYPTO_hash_to_aes_key (&sm->chk.key, &skey, &iv); - GNUNET_CRYPTO_aes_decrypt (prc->data, - prc->size, - &skey, - &iv, - pt); + if (-1 == GNUNET_CRYPTO_aes_decrypt (prc->data, + prc->size, + &skey, + &iv, + pt)) + { + GNUNET_break (0); + dc->emsg = GNUNET_strdup ("internal error decrypting content"); + goto signal_error; + } off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), sm->offset, sm->depth, diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 21fd7e8f1..da61cea57 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -574,11 +574,15 @@ process_kblock (struct GNUNET_FS_SearchContext *sc, } /* decrypt */ GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); - GNUNET_CRYPTO_aes_decrypt (&kb[1], - size - sizeof (struct KBlock), - &skey, - &iv, - pt); + if (-1 == GNUNET_CRYPTO_aes_decrypt (&kb[1], + size - sizeof (struct KBlock), + &skey, + &iv, + pt)) + { + GNUNET_break (0); + return; + } /* parse */ eos = memchr (pt, 0, sizeof (pt)); if (NULL == eos) @@ -654,11 +658,15 @@ process_nblock (struct GNUNET_FS_SearchContext *sc, } /* decrypt */ GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); - GNUNET_CRYPTO_aes_decrypt (&nb[1], - size - sizeof (struct NBlock), - &skey, - &iv, - pt); + if (-1 == GNUNET_CRYPTO_aes_decrypt (&nb[1], + size - sizeof (struct NBlock), + &skey, + &iv, + pt)) + { + GNUNET_break (0); + return; + } /* parse */ eos = memchr (pt, 0, sizeof (pt)); if (NULL == eos) @@ -736,11 +744,15 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, strlen (identifier), &key); GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); - GNUNET_CRYPTO_aes_decrypt (&sb[1], - len, - &skey, - &iv, - pt); + if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1], + len, + &skey, + &iv, + pt)) + { + GNUNET_break (0); + return; + } /* parse */ off = GNUNET_STRINGS_buffer_tokenize (pt, len, diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 874c2ecc5..90d0cabaf 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -760,7 +760,7 @@ is_closer (const GNUNET_HashCode *key, * targets for (or NULL for none) * @param key ID of the peer * @param value 'struct ConnectedPeer' of the peer - * @return GNUNET_YES (always continue iteration)2 + * @return GNUNET_YES (always continue iteration) */ static int consider_migration (void *cls, @@ -842,11 +842,12 @@ consider_migration (void *cls, } if (msize == 0) return GNUNET_YES; /* no content available */ +#if DEBUG_FS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Trying to migrate `%s' (%u bytes) to `%s'\n", - GNUNET_h2s (&mb->query), + "Trying to migrate at least %u bytes to peer `%s'\n", msize, - GNUNET_i2s (&cppid)); + GNUNET_h2s (key)); +#endif cp->cth = GNUNET_CORE_notify_transmit_ready (core, 0, GNUNET_TIME_UNIT_FOREVER_REL, diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 7c1f53d4b..63c605705 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c @@ -606,10 +606,11 @@ discard_hosts_helper (void *cls, const char *fn) int size; size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); - if ((size < sizeof (struct GNUNET_MessageHeader)) && (0 != UNLINK (fn))) + if (size < sizeof (struct GNUNET_MessageHeader)) { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | - GNUNET_ERROR_TYPE_BULK, "unlink", fn); + if (0 != UNLINK (fn)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | + GNUNET_ERROR_TYPE_BULK, "unlink", fn); return GNUNET_OK; } hello = (const struct GNUNET_HELLO_Message *) buffer; diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 4ba459c46..3289745b1 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c @@ -196,7 +196,7 @@ static int try_connect (struct GNUNET_STATISTICS_Handle *ret) { if (ret->client != NULL) - return GNUNET_OK; + return GNUNET_YES; ret->client = GNUNET_CLIENT_connect (ret->sched, "statistics", ret->cfg); if (ret->client != NULL) return GNUNET_YES; @@ -235,9 +235,12 @@ finish (struct GNUNET_STATISTICS_Handle *h, int code) struct GNUNET_STATISTICS_GetHandle *pos = h->current; h->current = NULL; schedule_action (h); - if (pos->cont != NULL) - pos->cont (pos->cls, code); - free_action_item (pos); + if (pos != NULL) + { + if (pos->cont != NULL) + pos->cont (pos->cls, code); + free_action_item (pos); + } } diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index a73c64da0..e1c904622 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -1068,17 +1068,16 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) return; } if (GNUNET_OK != GNUNET_DISK_file_test (fn)) - GNUNET_DISK_fn_write (fn, NULL, 0, GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_fn_write (fn, NULL, 0, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); if (0 != STAT (fn, &frstat)) { if ((friends_only) || (minimum_friend_count > 0)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Could not read friends list `%s'\n"), fn); - GNUNET_free (fn); - return; - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Could not read friends list `%s'\n"), fn); + GNUNET_free (fn); + return; } if (frstat.st_size == 0) { diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index fca1b1f15..7e3bc080c 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -443,7 +443,11 @@ tcp_address_to_string (void *cls, GNUNET_break (0); return NULL; } - inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); + if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); + return NULL; + } GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u", @@ -859,9 +863,13 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen) case AF_INET: if (addrlen != sizeof (struct sockaddr_in)) return; - inet_ntop (AF_INET, - &((struct sockaddr_in *) sa)->sin_addr, - inet4, INET_ADDRSTRLEN); + if (NULL == inet_ntop (AF_INET, + &((struct sockaddr_in *) sa)->sin_addr, + inet4, INET_ADDRSTRLEN)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); + return; + } address_as_string = GNUNET_strdup (inet4); break; case AF_INET6: diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 82ccaa8cb..5afb804dc 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -581,9 +581,13 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen) case AF_INET: if (addrlen != sizeof (struct sockaddr_in)) return; - inet_ntop (AF_INET, - &((struct sockaddr_in *) sa)->sin_addr, - inet4, INET_ADDRSTRLEN); + if (NULL == inet_ntop (AF_INET, + &((struct sockaddr_in *) sa)->sin_addr, + inet4, INET_ADDRSTRLEN)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); + return; + } address_as_string = GNUNET_strdup (inet4); break; case AF_INET6: @@ -1097,7 +1101,13 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, con if (sender_addr->ss_family == AF_INET) { memset(&addr_buf, 0, sizeof(addr_buf)); - inet_ntop(AF_INET, &((struct sockaddr_in *) sender_addr)->sin_addr, addr_buf, INET_ADDRSTRLEN); + if (NULL == inet_ntop (AF_INET, + &((struct sockaddr_in *) sender_addr)->sin_addr, addr_buf, + INET_ADDRSTRLEN)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); + return; + } outgoing_probe = find_probe(plugin, &addr_buf[0]); if (outgoing_probe != NULL) { diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 7e6750e8b..a9f79fe96 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -430,6 +430,11 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, GNUNET_assert (0 != proc); ret = waitpid (proc, &status, WNOHANG); + if (ret < 0) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); + return GNUNET_SYSERR; + } if (0 == ret) { *type = GNUNET_OS_PROCESS_RUNNING; -- 2.25.1