diff options
Diffstat (limited to 'src/social/gnunet-service-social.c')
-rw-r--r-- | src/social/gnunet-service-social.c | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c index 5b2a8ba9b..31e3a3dc2 100644 --- a/src/social/gnunet-service-social.c +++ b/src/social/gnunet-service-social.c | |||
@@ -503,17 +503,18 @@ cleanup_guest (struct Guest *gst) | |||
503 | struct GNUNET_CONTAINER_MultiHashMap * | 503 | struct GNUNET_CONTAINER_MultiHashMap * |
504 | plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, | 504 | plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, |
505 | &plc->pub_key_hash); | 505 | &plc->pub_key_hash); |
506 | GNUNET_assert (NULL != plc_gst); | 506 | if (NULL != plc_gst) |
507 | GNUNET_CONTAINER_multihashmap_remove (plc_gst, &plc->ego_pub_hash, gst); | ||
508 | |||
509 | if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst)) | ||
510 | { | 507 | { |
511 | GNUNET_CONTAINER_multihashmap_remove (place_guests, &plc->pub_key_hash, | 508 | GNUNET_CONTAINER_multihashmap_remove (plc_gst, &plc->ego_pub_hash, gst); |
512 | plc_gst); | 509 | |
513 | GNUNET_CONTAINER_multihashmap_destroy (plc_gst); | 510 | if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst)) |
511 | { | ||
512 | GNUNET_CONTAINER_multihashmap_remove (place_guests, &plc->pub_key_hash, | ||
513 | plc_gst); | ||
514 | GNUNET_CONTAINER_multihashmap_destroy (plc_gst); | ||
515 | } | ||
514 | } | 516 | } |
515 | GNUNET_CONTAINER_multihashmap_remove (guests, &plc->pub_key_hash, gst); | 517 | GNUNET_CONTAINER_multihashmap_remove (guests, &plc->pub_key_hash, gst); |
516 | |||
517 | if (NULL != gst->join_req) | 518 | if (NULL != gst->join_req) |
518 | GNUNET_free (gst->join_req); | 519 | GNUNET_free (gst->join_req); |
519 | if (NULL != gst->relays) | 520 | if (NULL != gst->relays) |
@@ -1391,19 +1392,27 @@ msg_proc_parse (const struct MsgProcRequest *mpreq, | |||
1391 | const char **method_prefix, | 1392 | const char **method_prefix, |
1392 | struct GNUNET_HashCode *method_hash) | 1393 | struct GNUNET_HashCode *method_hash) |
1393 | { | 1394 | { |
1394 | uint8_t method_size = ntohs (mpreq->header.size) - sizeof (*mpreq); | 1395 | ssize_t method_size = ntohs (mpreq->header.size) - sizeof (*mpreq); |
1395 | uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &mpreq[1], | 1396 | uint16_t offset; |
1396 | method_size, 1, method_prefix); | ||
1397 | 1397 | ||
1398 | if (0 == offset || offset != method_size || *method_prefix == NULL) | 1398 | if (method_size < 0) |
1399 | { | 1399 | { |
1400 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1400 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1401 | "offset = %u, method_size = %u, method_name = %s\n", | 1401 | "MsgProcRequest has invalid size\n"); |
1402 | offset, method_size, *method_prefix); | ||
1403 | return GNUNET_SYSERR; | 1402 | return GNUNET_SYSERR; |
1404 | } | 1403 | } |
1405 | 1404 | ||
1406 | GNUNET_CRYPTO_hash (*method_prefix, method_size, method_hash); | 1405 | offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &mpreq[1], |
1406 | method_size, | ||
1407 | 1, | ||
1408 | method_prefix); | ||
1409 | if (0 == offset || offset != method_size || *method_prefix == NULL) | ||
1410 | { | ||
1411 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1412 | "MsgProcRequest contains invalid method\n"); | ||
1413 | return GNUNET_SYSERR; | ||
1414 | } | ||
1415 | GNUNET_CRYPTO_hash (*method_prefix, (size_t) method_size, method_hash); | ||
1407 | *flags = ntohl (mpreq->flags); | 1416 | *flags = ntohl (mpreq->flags); |
1408 | return GNUNET_OK; | 1417 | return GNUNET_OK; |
1409 | } | 1418 | } |
@@ -1755,6 +1764,7 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst) | |||
1755 | struct GNUNET_CONTAINER_MultiHashMap * | 1764 | struct GNUNET_CONTAINER_MultiHashMap * |
1756 | plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, &place_pub_hash); | 1765 | plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, &place_pub_hash); |
1757 | struct Guest *gst = NULL; | 1766 | struct Guest *gst = NULL; |
1767 | int new_guest; | ||
1758 | 1768 | ||
1759 | if (NULL != plc_gst) | 1769 | if (NULL != plc_gst) |
1760 | gst = GNUNET_CONTAINER_multihashmap_get (plc_gst, &ego_pub_hash); | 1770 | gst = GNUNET_CONTAINER_multihashmap_get (plc_gst, &ego_pub_hash); |
@@ -1763,9 +1773,12 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst) | |||
1763 | "plc_gst = %p, gst = %p\n", | 1773 | "plc_gst = %p, gst = %p\n", |
1764 | plc_gst, | 1774 | plc_gst, |
1765 | gst); | 1775 | gst); |
1776 | |||
1777 | new_guest = GNUNET_NO; | ||
1766 | if (NULL == gst) | 1778 | if (NULL == gst) |
1767 | { | 1779 | { |
1768 | gst = GNUNET_new (struct Guest); | 1780 | gst = GNUNET_new (struct Guest); |
1781 | new_guest = GNUNET_YES; | ||
1769 | } | 1782 | } |
1770 | if (NULL == gst->slave) | 1783 | if (NULL == gst->slave) |
1771 | { | 1784 | { |
@@ -1841,6 +1854,9 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst) | |||
1841 | plc_gst = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); | 1854 | plc_gst = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); |
1842 | (void) GNUNET_CONTAINER_multihashmap_put (place_guests, &plc->pub_key_hash, plc_gst, | 1855 | (void) GNUNET_CONTAINER_multihashmap_put (place_guests, &plc->pub_key_hash, plc_gst, |
1843 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 1856 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
1857 | } | ||
1858 | if (GNUNET_YES == new_guest) | ||
1859 | { | ||
1844 | (void) GNUNET_CONTAINER_multihashmap_put (plc_gst, &plc->ego_pub_hash, gst, | 1860 | (void) GNUNET_CONTAINER_multihashmap_put (plc_gst, &plc->ego_pub_hash, gst, |
1845 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 1861 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
1846 | (void) GNUNET_CONTAINER_multihashmap_put (guests, &plc->pub_key_hash, gst, | 1862 | (void) GNUNET_CONTAINER_multihashmap_put (guests, &plc->pub_key_hash, gst, |
@@ -1862,6 +1878,7 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst) | |||
1862 | ret = GNUNET_YES; | 1878 | ret = GNUNET_YES; |
1863 | } | 1879 | } |
1864 | 1880 | ||
1881 | // TODO: explain why free(gst) not necessary | ||
1865 | if (NULL != ret_gst) | 1882 | if (NULL != ret_gst) |
1866 | *ret_gst = gst; | 1883 | *ret_gst = gst; |
1867 | return ret; | 1884 | return ret; |
@@ -2134,20 +2151,34 @@ handle_client_app_connect (void *cls, | |||
2134 | { | 2151 | { |
2135 | struct Client *c = cls; | 2152 | struct Client *c = cls; |
2136 | struct GNUNET_SERVICE_Client *client = c->client; | 2153 | struct GNUNET_SERVICE_Client *client = c->client; |
2137 | 2154 | ssize_t app_id_size = ntohs (creq->header.size) - sizeof (*creq); | |
2138 | uint8_t app_id_size = ntohs (creq->header.size) - sizeof (*creq); | ||
2139 | const char *app_id = NULL; | 2155 | const char *app_id = NULL; |
2140 | uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &creq[1], | 2156 | uint16_t offset; |
2141 | app_id_size, 1, &app_id); | 2157 | |
2158 | if (app_id_size < 0) | ||
2159 | { | ||
2160 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2161 | "AppConnectRequest has invalid size\n"); | ||
2162 | GNUNET_break (0); | ||
2163 | GNUNET_SERVICE_client_drop (client); | ||
2164 | return; | ||
2165 | } | ||
2166 | |||
2167 | offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &creq[1], | ||
2168 | (size_t) app_id_size, | ||
2169 | 1, | ||
2170 | &app_id); | ||
2142 | if (0 == offset || offset != app_id_size) | 2171 | if (0 == offset || offset != app_id_size) |
2143 | { | 2172 | { |
2173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2174 | "AppConnectRequest contains invalid app ID\n"); | ||
2144 | GNUNET_break (0); | 2175 | GNUNET_break (0); |
2145 | GNUNET_SERVICE_client_drop (client); | 2176 | GNUNET_SERVICE_client_drop (client); |
2146 | return; | 2177 | return; |
2147 | } | 2178 | } |
2148 | 2179 | ||
2149 | struct GNUNET_HashCode app_id_hash; | 2180 | struct GNUNET_HashCode app_id_hash; |
2150 | GNUNET_CRYPTO_hash (app_id, app_id_size, &app_id_hash); | 2181 | GNUNET_CRYPTO_hash (app_id, (size_t) app_id_size, &app_id_hash); |
2151 | 2182 | ||
2152 | GNUNET_CONTAINER_multihashmap_iterate (egos, ego_entry, client); | 2183 | GNUNET_CONTAINER_multihashmap_iterate (egos, ego_entry, client); |
2153 | app_notify_ego_end (client); | 2184 | app_notify_ego_end (client); |
@@ -2172,8 +2203,8 @@ handle_client_app_connect (void *cls, | |||
2172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2173 | "%p Application %s connected.\n", app, app_id); | 2204 | "%p Application %s connected.\n", app, app_id); |
2174 | 2205 | ||
2175 | c->app_id = GNUNET_malloc (app_id_size); | 2206 | c->app_id = GNUNET_malloc ((size_t) app_id_size); |
2176 | GNUNET_memcpy (c->app_id, app_id, app_id_size); | 2207 | GNUNET_memcpy (c->app_id, app_id, (size_t) app_id_size); |
2177 | 2208 | ||
2178 | GNUNET_SERVICE_client_continue (client); | 2209 | GNUNET_SERVICE_client_continue (client); |
2179 | } | 2210 | } |