aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent3a18658cf9196ecd8e55d5231818e6ee3b242a43 (diff)
downloadgnunet-8dea30580ceaa571c9d85b5e8a563201ed622ed7.tar.gz
gnunet-8dea30580ceaa571c9d85b5e8a563201ed622ed7.zip
fix potential use of uninitialized key
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs_search.c19
-rw-r--r--src/fs/fs_uri.c25
-rw-r--r--src/include/gnunet_fs_service.h3
3 files changed, 36 insertions, 11 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,
568 568
569 /* check if new */ 569 /* check if new */
570 GNUNET_assert (NULL != sc); 570 GNUNET_assert (NULL != sc);
571 GNUNET_FS_uri_to_key (uri, &key); 571 if (GNUNET_OK !=
572 GNUNET_FS_uri_to_key (uri,
573 &key))
574 {
575 GNUNET_break_op (0);
576 return;
577 }
572 if (GNUNET_SYSERR == 578 if (GNUNET_SYSERR ==
573 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, 579 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results,
574 &key, 580 &key,
@@ -680,8 +686,15 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
680 686
681 /* check if new */ 687 /* check if new */
682 GNUNET_assert (NULL != sc); 688 GNUNET_assert (NULL != sc);
683 GNUNET_FS_uri_to_key (uri, &key); 689 if (GNUNET_OK !=
684 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, &uri->data.chk.chk.query, 690 GNUNET_FS_uri_to_key (uri,
691 &key))
692 {
693 GNUNET_break (0);
694 return;
695 }
696 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
697 &uri->data.chk.chk.query,
685 &key); 698 &key);
686 if (GNUNET_SYSERR == 699 if (GNUNET_SYSERR ==
687 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key, 700 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 @@
96 * 96 *
97 * @param uri uri to convert to a unique key 97 * @param uri uri to convert to a unique key
98 * @param key where to store the unique key 98 * @param key where to store the unique key
99 * @return #GNUNET_OK on success
99 */ 100 */
100void 101int
101GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, 102GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
102 struct GNUNET_HashCode *key) 103 struct GNUNET_HashCode *key)
103{ 104{
@@ -105,25 +106,35 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
105 { 106 {
106 case GNUNET_FS_URI_CHK: 107 case GNUNET_FS_URI_CHK:
107 *key = uri->data.chk.chk.query; 108 *key = uri->data.chk.chk.query;
108 return; 109 return GNUNET_OK;
109 case GNUNET_FS_URI_SKS: 110 case GNUNET_FS_URI_SKS:
110 GNUNET_CRYPTO_hash (uri->data.sks.identifier, 111 GNUNET_CRYPTO_hash (uri->data.sks.identifier,
111 strlen (uri->data.sks.identifier), key); 112 strlen (uri->data.sks.identifier),
112 break; 113 key);
114 return GNUNET_OK;
113 case GNUNET_FS_URI_KSK: 115 case GNUNET_FS_URI_KSK:
114 if (uri->data.ksk.keywordCount > 0) 116 if (uri->data.ksk.keywordCount > 0)
117 {
115 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], 118 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
116 strlen (uri->data.ksk.keywords[0]), key); 119 strlen (uri->data.ksk.keywords[0]),
120 key);
121 return GNUNET_OK;
122 }
123 else
124 {
125 memset (key, 0, sizeof (struct GNUNET_HashCode));
126 return GNUNET_SYSERR;
127 }
117 break; 128 break;
118 case GNUNET_FS_URI_LOC: 129 case GNUNET_FS_URI_LOC:
119 GNUNET_CRYPTO_hash (&uri->data.loc.fi, 130 GNUNET_CRYPTO_hash (&uri->data.loc.fi,
120 sizeof (struct FileIdentifier) + 131 sizeof (struct FileIdentifier) +
121 sizeof (struct GNUNET_PeerIdentity), 132 sizeof (struct GNUNET_PeerIdentity),
122 key); 133 key);
123 break; 134 return GNUNET_OK;
124 default: 135 default:
125 memset (key, 0, sizeof (struct GNUNET_HashCode)); 136 memset (key, 0, sizeof (struct GNUNET_HashCode));
126 break; 137 return GNUNET_SYSERR;
127 } 138 }
128} 139}
129 140
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
109 * 109 *
110 * @param uri uri to convert to a unique key 110 * @param uri uri to convert to a unique key
111 * @param key wherer to store the unique key 111 * @param key wherer to store the unique key
112 * @return #GNUNET_OK on success
112 */ 113 */
113void 114int
114GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, 115GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
115 struct GNUNET_HashCode *key); 116 struct GNUNET_HashCode *key);
116 117