- fix coverity
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Thu, 7 Jul 2016 12:17:52 +0000 (12:17 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Thu, 7 Jul 2016 12:17:52 +0000 (12:17 +0000)
src/identity-provider/gnunet-identity-token.c
src/identity-provider/gnunet-service-identity-provider.c
src/identity-provider/identity_provider_api.c
src/identity-provider/identity_token.c
src/identity-provider/plugin_rest_identity_provider.c

index ad4aae78a9b7fe1447df5e79a22f94da11ba2002..3d28308356740855af11f822fb105dae65252095 100644 (file)
@@ -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
index 0a690e2d3a2e05ec237b9d41cb7b852113156f66..32a6950912f58f500719e6cad4212c6b3ee79bad 100644 (file)
@@ -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);
index f3280cb18a8ae393f03c9cfdb63e76dfcb01542c..53081ae056766c5a45e4bc8863bacfa9949f2fe7 100644 (file)
@@ -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;
   }
index 8a90138ecfa58640fe1a529d6e1f83ba84453c04..8f35170fb9f125db2121dbc71a2d97f904344bd4 100644 (file)
@@ -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;
   }
index 207a15cc5d3c6e69b6e41824659ba1a4f5f04949..c0b018798e6d2630bc8f46c9b35313bfadf460ed 100644 (file)
@@ -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,