summaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-01-06 21:05:03 +0100
committerChristian Grothoff <christian@grothoff.org>2018-01-06 21:05:03 +0100
commit8dea30580ceaa571c9d85b5e8a563201ed622ed7 (patch)
tree97cabce64f3d7c87672fad8d3ab8783ac2760187 /src/fs
parent3a18658cf9196ecd8e55d5231818e6ee3b242a43 (diff)
fix potential use of uninitialized key
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs_search.c19
-rw-r--r--src/fs/fs_uri.c25
2 files changed, 34 insertions, 10 deletions
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;
}
}