From 8dea30580ceaa571c9d85b5e8a563201ed622ed7 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 6 Jan 2018 21:05:03 +0100 Subject: fix potential use of uninitialized key --- src/fs/fs_search.c | 19 ++++++++++++++++--- src/fs/fs_uri.c | 25 ++++++++++++++++++------- src/include/gnunet_fs_service.h | 3 ++- 3 files changed, 36 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 8c6f5edcf..83aae2fc5 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -568,7 +568,13 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, /* check if new */ GNUNET_assert (NULL != sc); - GNUNET_FS_uri_to_key (uri, &key); + if (GNUNET_OK != + GNUNET_FS_uri_to_key (uri, + &key)) + { + GNUNET_break_op (0); + return; + } if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, &key, @@ -680,8 +686,15 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, /* check if new */ GNUNET_assert (NULL != sc); - GNUNET_FS_uri_to_key (uri, &key); - GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, &uri->data.chk.chk.query, + if (GNUNET_OK != + GNUNET_FS_uri_to_key (uri, + &key)) + { + GNUNET_break (0); + return; + } + GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, + &uri->data.chk.chk.query, &key); if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key, diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 11968b750..b90c75981 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c @@ -96,8 +96,9 @@ * * @param uri uri to convert to a unique key * @param key where to store the unique key + * @return #GNUNET_OK on success */ -void +int GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, struct GNUNET_HashCode *key) { @@ -105,25 +106,35 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, { case GNUNET_FS_URI_CHK: *key = uri->data.chk.chk.query; - return; + return GNUNET_OK; case GNUNET_FS_URI_SKS: GNUNET_CRYPTO_hash (uri->data.sks.identifier, - strlen (uri->data.sks.identifier), key); - break; + strlen (uri->data.sks.identifier), + key); + return GNUNET_OK; case GNUNET_FS_URI_KSK: if (uri->data.ksk.keywordCount > 0) + { GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], - strlen (uri->data.ksk.keywords[0]), key); + strlen (uri->data.ksk.keywords[0]), + key); + return GNUNET_OK; + } + else + { + memset (key, 0, sizeof (struct GNUNET_HashCode)); + return GNUNET_SYSERR; + } break; case GNUNET_FS_URI_LOC: GNUNET_CRYPTO_hash (&uri->data.loc.fi, sizeof (struct FileIdentifier) + sizeof (struct GNUNET_PeerIdentity), key); - break; + return GNUNET_OK; default: memset (key, 0, sizeof (struct GNUNET_HashCode)); - break; + return GNUNET_SYSERR; } } diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index ac418072e..cbad374b5 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -109,8 +109,9 @@ typedef int * * @param uri uri to convert to a unique key * @param key wherer to store the unique key + * @return #GNUNET_OK on success */ -void +int GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, struct GNUNET_HashCode *key); -- cgit v1.2.3