From: Martin Schanzenbach Date: Thu, 7 Jul 2016 12:17:52 +0000 (+0000) Subject: - fix coverity X-Git-Tag: initial-import-from-subversion-38251~589 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6e956d0ced722dbfbd8adeb303ad7006aed6b025;p=oweals%2Fgnunet.git - fix coverity --- diff --git a/src/identity-provider/gnunet-identity-token.c b/src/identity-provider/gnunet-identity-token.c index ad4aae78a..3d2830835 100644 --- a/src/identity-provider/gnunet-identity-token.c +++ b/src/identity-provider/gnunet-identity-token.c @@ -33,6 +33,11 @@ run (void *cls, struct GNUNET_CRYPTO_EcdsaPublicKey key; struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; struct GNUNET_CRYPTO_EcdsaSignature sig; + + GNUNET_assert (NULL != header_b64); + GNUNET_assert (NULL != payload_b64); + GNUNET_assert (NULL != signature_b32); + //Decode payload GNUNET_STRINGS_base64_decode (payload_b64, strlen (payload_b64), @@ -54,16 +59,25 @@ run (void *cls, purpose->size = htonl(sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + strlen (data)); purpose->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN); memcpy (&purpose[1], data, strlen(data)); + GNUNET_free (data); + GNUNET_free (header_b64); + GNUNET_free (header_b64); + if (print_token) + printf ("Token:\nHeader:\t\t%s\nPayload:\t%s\n", header, payload); + GNUNET_free (header); + GNUNET_free (payload); payload_json = json_loads (payload, 0, &error); if ((NULL == payload_json) || !json_is_object (payload_json)) { + GNUNET_free (val); return; } keystring_json = json_object_get (payload_json, "iss"); if (!json_is_string (keystring_json)) { + GNUNET_free (val); return; } keystring = json_string_value (keystring_json); @@ -71,6 +85,7 @@ run (void *cls, strlen (keystring), &key)) { + GNUNET_free (val); return; } GNUNET_STRINGS_string_to_data (signature_b32, @@ -78,19 +93,17 @@ run (void *cls, &sig, sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); - if (print_token) { - printf ("Token:\nHeader:\t\t%s\nPayload:\t%s\nSignature:\t%s\n", header, payload, keystring); - } + if (print_token) + printf ("Signature:\t%s\n", keystring); if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN, purpose, &sig, &key)) - { printf("Signature not OK!\n"); - return; - } - printf("Signature OK!\n"); + else + printf("Signature OK!\n"); + GNUNET_free (val); return; } int diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/identity-provider/gnunet-service-identity-provider.c index 0a690e2d3..32a695091 100644 --- a/src/identity-provider/gnunet-service-identity-provider.c +++ b/src/identity-provider/gnunet-service-identity-provider.c @@ -365,13 +365,13 @@ handle_token_update (void *cls) { if (0 == strcmp (attr->name, "exp")) { - sscanf (attr->val_head->value, + GNUNET_assert (1 == sscanf (attr->val_head->value, "%"SCNu64, - &token_exp.abs_value_us); + &token_exp.abs_value_us)); } else if (0 == strcmp (attr->name, "nbf")) { - sscanf (attr->val_head->value, + GNUNET_assert (1 == sscanf (attr->val_head->value, "%"SCNu64, - &token_nbf.abs_value_us); + &token_nbf.abs_value_us)); } } token_rel_exp = GNUNET_TIME_absolute_get_difference (token_nbf, token_exp); @@ -598,7 +598,7 @@ token_collect (void *cls, //Get metadata and decrypt token ecdhe_privkey = *((struct GNUNET_CRYPTO_EcdhePrivateKey *)token_metadata_record->data); - aud_key = (struct GNUNET_CRYPTO_EcdsaPublicKey *)&ecdhe_privkey+sizeof(struct GNUNET_CRYPTO_EcdhePrivateKey); + aud_key = (struct GNUNET_CRYPTO_EcdsaPublicKey *)&(&ecdhe_privkey)[1]; scopes = GNUNET_strdup ((char*) aud_key+sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); token_parse2 (token_record->data, @@ -698,10 +698,10 @@ attribute_collect (void *cls, val); } } - GNUNET_CONTAINER_multihashmap_put (ego_entry->attr_map, + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (ego_entry->attr_map, &key, attr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); GNUNET_NAMESTORE_zone_iterator_next (ns_it); return; } @@ -1177,7 +1177,7 @@ process_lookup_result (void *cls, uint32_t rd_count, "Number of tokens %d != 2.", rd_count); cleanup_exchange_handle (handle); - GNUNET_SCHEDULER_add_now (&do_shutdown, handle); + GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); return; } @@ -1362,6 +1362,8 @@ find_existing_token (void *cls, tmp2, tmp); GNUNET_free (tmp_scopes); + GNUNET_free (tmp2); + GNUNET_free (tmp); GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it); return; } @@ -1389,7 +1391,8 @@ find_existing_token (void *cls, GNUNET_free (tmp_scopes); //All scopes in token are also in request. Now //Check length - if (GNUNET_CONTAINER_multihashmap_size (handle->attr_map) == scope_count_token) + if ((NULL != handle->attr_map) && + (GNUNET_CONTAINER_multihashmap_size (handle->attr_map) == scope_count_token)) { //We have an existing token handle->label = GNUNET_strdup (lbl); diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c index f3280cb18..53081ae05 100644 --- a/src/identity-provider/identity_provider_api.c +++ b/src/identity-provider/identity_provider_api.c @@ -511,6 +511,7 @@ GNUNET_IDENTITY_PROVIDER_exchange_ticket (struct GNUNET_IDENTITY_PROVIDER_Handle slen = strlen (ticket_str) + 1; if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_PROVIDER_ExchangeMessage)) { + GNUNET_free (ticket_str); GNUNET_break (0); return NULL; } diff --git a/src/identity-provider/identity_token.c b/src/identity-provider/identity_token.c index 8a90138ec..8f35170fb 100644 --- a/src/identity-provider/identity_token.c +++ b/src/identity-provider/identity_token.c @@ -424,6 +424,9 @@ token_parse (const char* raw_data, GNUNET_asprintf (&tmp_buf, "%s", raw_data); ecdh_pubkey_str = strtok (tmp_buf, ","); enc_token_str = strtok (NULL, ","); + + GNUNET_assert (NULL != ecdh_pubkey_str); + GNUNET_assert (NULL != enc_token_str); GNUNET_STRINGS_string_to_data (ecdh_pubkey_str, strlen (ecdh_pubkey_str), @@ -547,6 +550,7 @@ token_to_string (const struct IdentityToken *token, GNUNET_free (signature_target); GNUNET_free (payload_str); GNUNET_free (payload_base64); + GNUNET_free (header_base64); GNUNET_free (purpose); return GNUNET_SYSERR; } diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c index 207a15cc5..c0b018798 100644 --- a/src/identity-provider/plugin_rest_identity_provider.c +++ b/src/identity-provider/plugin_rest_identity_provider.c @@ -583,7 +583,7 @@ issue_token_cont (struct GNUNET_REST_RequestHandle *con, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request nonce: %s\n", nonce_str); - sscanf (nonce_str, "%"SCNu64, &nonce); + GNUNET_assert (1 == sscanf (nonce_str, "%"SCNu64, &nonce)); //Get expiration for token from URL parameter GNUNET_CRYPTO_hash (GNUNET_IDENTITY_TOKEN_EXP_STRING,