diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-01-06 16:46:59 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-01-06 16:46:59 +0100 |
commit | ab9f9e5146695367b9215b5a611927f91aec1cff (patch) | |
tree | 70c831a4575dc5f7f23ba1668ca236d453b4d241 | |
parent | 6ddfa55804cca3706e4f9fe803a76b7bc5310d47 (diff) | |
download | gnunet-ab9f9e5146695367b9215b5a611927f91aec1cff.tar.gz gnunet-ab9f9e5146695367b9215b5a611927f91aec1cff.zip |
misc peerinfo fixes; signed/unsinged cmps, warnings, unchecked return value
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 83a7b589b..bdb6e5e0d 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -198,6 +198,8 @@ count_addresses (void *cls, | |||
198 | { | 198 | { |
199 | unsigned int *cnt = cls; | 199 | unsigned int *cnt = cls; |
200 | 200 | ||
201 | (void) address; | ||
202 | (void) expiration; | ||
201 | (*cnt)++; | 203 | (*cnt)++; |
202 | return GNUNET_OK; | 204 | return GNUNET_OK; |
203 | } | 205 | } |
@@ -290,7 +292,7 @@ read_host_file (const char *fn, | |||
290 | const struct GNUNET_HELLO_Message *hello; | 292 | const struct GNUNET_HELLO_Message *hello; |
291 | struct GNUNET_HELLO_Message *hello_clean; | 293 | struct GNUNET_HELLO_Message *hello_clean; |
292 | size_t read_pos; | 294 | size_t read_pos; |
293 | int size_hello; | 295 | uint16_t size_hello; |
294 | 296 | ||
295 | r->friend_only_hello = NULL; | 297 | r->friend_only_hello = NULL; |
296 | r->hello = NULL; | 298 | r->hello = NULL; |
@@ -304,7 +306,8 @@ read_host_file (const char *fn, | |||
304 | "Read %d bytes from `%s'\n", | 306 | "Read %d bytes from `%s'\n", |
305 | (int) size_total, | 307 | (int) size_total, |
306 | fn); | 308 | fn); |
307 | if (size_total < sizeof (struct GNUNET_MessageHeader)) | 309 | if ( (size_total < 0) || |
310 | (((size_t) size_total) < sizeof (struct GNUNET_MessageHeader)) ) | ||
308 | { | 311 | { |
309 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 312 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
310 | _("Failed to parse HELLO in file `%s': %s\n"), | 313 | _("Failed to parse HELLO in file `%s': %s\n"), |
@@ -320,12 +323,12 @@ read_host_file (const char *fn, | |||
320 | } | 323 | } |
321 | 324 | ||
322 | read_pos = 0; | 325 | read_pos = 0; |
323 | while (read_pos < size_total) | 326 | while (read_pos < (size_t) size_total) |
324 | { | 327 | { |
325 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; | 328 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; |
326 | size_hello = GNUNET_HELLO_size (hello); | 329 | size_hello = GNUNET_HELLO_size (hello); |
327 | if ( (0 == size_hello) || | 330 | if ( (0 == size_hello) || |
328 | (size_total - read_pos < size_hello) ) | 331 | (((size_t) size_total) - read_pos < size_hello) ) |
329 | { | 332 | { |
330 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 333 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
331 | _("Failed to parse HELLO in file `%s'\n"), | 334 | _("Failed to parse HELLO in file `%s'\n"), |
@@ -640,6 +643,7 @@ cron_scan_directory_data_hosts (void *cls) | |||
640 | static unsigned int retries; | 643 | static unsigned int retries; |
641 | struct DirScanContext dsc; | 644 | struct DirScanContext dsc; |
642 | 645 | ||
646 | (void) cls; | ||
643 | cron_scan = NULL; | 647 | cron_scan = NULL; |
644 | if (GNUNET_SYSERR == | 648 | if (GNUNET_SYSERR == |
645 | GNUNET_DISK_directory_create (networkIdDirectory)) | 649 | GNUNET_DISK_directory_create (networkIdDirectory)) |
@@ -730,7 +734,7 @@ update_hello (const struct GNUNET_PeerIdentity *peer, | |||
730 | int friend_hello_type; | 734 | int friend_hello_type; |
731 | int store_hello; | 735 | int store_hello; |
732 | int store_friend_hello; | 736 | int store_friend_hello; |
733 | int pos; | 737 | unsigned int pos; |
734 | char *buffer; | 738 | char *buffer; |
735 | 739 | ||
736 | host = GNUNET_CONTAINER_multipeermap_get (hostmap, peer); | 740 | host = GNUNET_CONTAINER_multipeermap_get (hostmap, peer); |
@@ -849,8 +853,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer, | |||
849 | if (GNUNET_YES == store_friend_hello) | 853 | if (GNUNET_YES == store_friend_hello) |
850 | { | 854 | { |
851 | GNUNET_memcpy (&buffer[pos], | 855 | GNUNET_memcpy (&buffer[pos], |
852 | host->friend_only_hello, | 856 | host->friend_only_hello, |
853 | GNUNET_HELLO_size (host->friend_only_hello)); | 857 | GNUNET_HELLO_size (host->friend_only_hello)); |
854 | pos += GNUNET_HELLO_size (host->friend_only_hello); | 858 | pos += GNUNET_HELLO_size (host->friend_only_hello); |
855 | } | 859 | } |
856 | GNUNET_assert (pos == size); | 860 | GNUNET_assert (pos == size); |
@@ -988,16 +992,31 @@ discard_hosts_helper (void *cls, | |||
988 | unsigned int cnt; | 992 | unsigned int cnt; |
989 | char *writebuffer; | 993 | char *writebuffer; |
990 | uint64_t fsize; | 994 | uint64_t fsize; |
995 | |||
996 | if (GNUNET_OK != | ||
997 | GNUNET_DISK_file_size (fn, | ||
998 | &fsize, | ||
999 | GNUNET_YES, | ||
1000 | GNUNET_YES)) | ||
1001 | { | ||
1002 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | ||
1003 | GNUNET_ERROR_TYPE_BULK, | ||
1004 | "fstat", | ||
1005 | fn); | ||
1006 | return GNUNET_OK; | ||
1007 | } | ||
1008 | read_size = GNUNET_DISK_fn_read (fn, | ||
1009 | buffer, | ||
1010 | sizeof (buffer)); | ||
991 | 1011 | ||
992 | GNUNET_DISK_file_size (fn, &fsize, GNUNET_YES, GNUNET_YES); | 1012 | if ( (read_size < (int) sizeof (struct GNUNET_MessageHeader)) || |
993 | read_size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | 1013 | (fsize > GNUNET_MAX_MESSAGE_SIZE) ) |
994 | |||
995 | if ((read_size < (int) sizeof (struct GNUNET_MessageHeader)) || | ||
996 | (fsize > GNUNET_MAX_MESSAGE_SIZE)) | ||
997 | { | 1014 | { |
998 | if (0 != UNLINK (fn)) | 1015 | if (0 != UNLINK (fn)) |
999 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 1016 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | |
1000 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); | 1017 | GNUNET_ERROR_TYPE_BULK, |
1018 | "unlink", | ||
1019 | fn); | ||
1001 | return GNUNET_OK; | 1020 | return GNUNET_OK; |
1002 | } | 1021 | } |
1003 | 1022 | ||
@@ -1074,6 +1093,7 @@ cron_clean_data_hosts (void *cls) | |||
1074 | { | 1093 | { |
1075 | struct GNUNET_TIME_Absolute now; | 1094 | struct GNUNET_TIME_Absolute now; |
1076 | 1095 | ||
1096 | (void) cls; | ||
1077 | cron_clean = NULL; | 1097 | cron_clean = NULL; |
1078 | now = GNUNET_TIME_absolute_get (); | 1098 | now = GNUNET_TIME_absolute_get (); |
1079 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 1099 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
@@ -1101,6 +1121,7 @@ check_hello (void *cls, | |||
1101 | { | 1121 | { |
1102 | struct GNUNET_PeerIdentity pid; | 1122 | struct GNUNET_PeerIdentity pid; |
1103 | 1123 | ||
1124 | (void) cls; | ||
1104 | if (GNUNET_OK != | 1125 | if (GNUNET_OK != |
1105 | GNUNET_HELLO_get_id (hello, | 1126 | GNUNET_HELLO_get_id (hello, |
1106 | &pid)) | 1127 | &pid)) |
@@ -1252,6 +1273,8 @@ client_connect_cb (void *cls, | |||
1252 | struct GNUNET_SERVICE_Client *client, | 1273 | struct GNUNET_SERVICE_Client *client, |
1253 | struct GNUNET_MQ_Handle *mq) | 1274 | struct GNUNET_MQ_Handle *mq) |
1254 | { | 1275 | { |
1276 | (void) cls; | ||
1277 | (void) mq; | ||
1255 | return client; | 1278 | return client; |
1256 | } | 1279 | } |
1257 | 1280 | ||
@@ -1268,6 +1291,7 @@ client_disconnect_cb (void *cls, | |||
1268 | struct GNUNET_SERVICE_Client *client, | 1291 | struct GNUNET_SERVICE_Client *client, |
1269 | void *app_ctx) | 1292 | void *app_ctx) |
1270 | { | 1293 | { |
1294 | (void) cls; | ||
1271 | GNUNET_assert (app_ctx == client); | 1295 | GNUNET_assert (app_ctx == client); |
1272 | } | 1296 | } |
1273 | 1297 | ||
@@ -1287,6 +1311,8 @@ free_host_entry (void *cls, | |||
1287 | { | 1311 | { |
1288 | struct HostEntry *he = value; | 1312 | struct HostEntry *he = value; |
1289 | 1313 | ||
1314 | (void) cls; | ||
1315 | (void) key; | ||
1290 | GNUNET_free_non_null (he->hello); | 1316 | GNUNET_free_non_null (he->hello); |
1291 | GNUNET_free_non_null (he->friend_only_hello); | 1317 | GNUNET_free_non_null (he->friend_only_hello); |
1292 | GNUNET_free (he); | 1318 | GNUNET_free (he); |
@@ -1302,6 +1328,7 @@ free_host_entry (void *cls, | |||
1302 | static void | 1328 | static void |
1303 | shutdown_task (void *cls) | 1329 | shutdown_task (void *cls) |
1304 | { | 1330 | { |
1331 | (void) cls; | ||
1305 | GNUNET_notification_context_destroy (notify_list); | 1332 | GNUNET_notification_context_destroy (notify_list); |
1306 | notify_list = NULL; | 1333 | notify_list = NULL; |
1307 | GNUNET_notification_context_destroy (notify_friend_only_list); | 1334 | GNUNET_notification_context_destroy (notify_friend_only_list); |
@@ -1353,6 +1380,8 @@ run (void *cls, | |||
1353 | int noio; | 1380 | int noio; |
1354 | int use_included; | 1381 | int use_included; |
1355 | 1382 | ||
1383 | (void) cls; | ||
1384 | (void) service; | ||
1356 | hostmap | 1385 | hostmap |
1357 | = GNUNET_CONTAINER_multipeermap_create (1024, | 1386 | = GNUNET_CONTAINER_multipeermap_create (1024, |
1358 | GNUNET_YES); | 1387 | GNUNET_YES); |