NULL pointer fix
[oweals/gnunet.git] / src / reclaim / oidc_helper.c
index 89e0920f000301cd6703190e251b759975f8e99b..d2789f978efe39e12cb8305f8e315f92604b2d8d 100644 (file)
@@ -1,22 +1,22 @@
 /*
-      This file is part of GNUnet
-      Copyright (C) 2010-2015 GNUnet e.V.
+   This file is part of GNUnet
+   Copyright (C) 2010-2015 GNUnet e.V.
 
-      GNUnet is free software: you can redistribute it and/or modify it
-      under the terms of the GNU Affero General Public License as published
-      by the Free Software Foundation, either version 3 of the License,
-      or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
-      GNUnet is distributed in the hope that it will be useful, but
-      WITHOUT ANY WARRANTY; without even the implied warranty of
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-      Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
-      You should have received a copy of the GNU Affero General Public License
-      along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     SPDX-License-Identifier: AGPL3.0-or-later
- */
+   SPDX-License-Identifier: AGPL3.0-or-later
  */
 
 /**
  * @file reclaim/oidc_helper.c
 #include "platform.h"
 #include <inttypes.h>
 #include <jansson.h>
-
 #include "gnunet_util_lib.h"
-
 #include "gnunet_reclaim_attribute_lib.h"
 #include "gnunet_reclaim_service.h"
 #include "gnunet_signatures.h"
 #include "oidc_helper.h"
+
+
 static char *
 create_jwt_header (void)
 {
@@ -303,16 +303,16 @@ derive_aes_key (struct GNUNET_CRYPTO_SymmetricSessionKey *key,
                      sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey),
                      ctx_key,
                      strlen (ctx_key),
-                     &key_material,
-                     sizeof (key_material),
+                     key_material,
+                     sizeof (struct GNUNET_HashCode),
                      NULL);
   GNUNET_CRYPTO_kdf (iv,
                      sizeof (
-                       struct GNUNET_CRYPTO_SymmetricInitializationVector),
+                             struct GNUNET_CRYPTO_SymmetricInitializationVector),
                      ctx_iv,
                      strlen (ctx_iv),
-                     &key_material,
-                     sizeof (key_material),
+                     key_material,
+                     sizeof (struct GNUNET_HashCode),
                      NULL);
 }
 
@@ -368,7 +368,7 @@ encrypt_payload (const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa_pub,
 
   calculate_key_pub (&key, &iv, ecdsa_pub, ecdh_priv);
   GNUNET_break (
-    GNUNET_CRYPTO_symmetric_encrypt (payload, payload_len, &key, &iv, buf));
+                GNUNET_CRYPTO_symmetric_encrypt (payload, payload_len, &key, &iv, buf));
 }
 
 
@@ -405,6 +405,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
   attrs_ser = NULL;
   signature_payload_len =
     sizeof (struct GNUNET_RECLAIM_Ticket) + sizeof (uint32_t);
+  
   if (NULL != attrs)
   {
     attr_list_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs);
@@ -415,10 +416,11 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
     attrs_ser = GNUNET_malloc (attr_list_len);
     GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, attrs_ser);
   }
+
   code_payload_len = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
-                     sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) +
-                     signature_payload_len +
-                     sizeof (struct GNUNET_CRYPTO_EcdsaSignature);
+    sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) +
+    signature_payload_len +
+    sizeof (struct GNUNET_CRYPTO_EcdsaSignature);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Length of data to encode: %lu\n",
               code_payload_len);
@@ -427,9 +429,10 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
   buf_ptr = plaintext;
   memcpy (buf_ptr, ticket, sizeof (struct GNUNET_RECLAIM_Ticket));
   buf_ptr += sizeof (struct GNUNET_RECLAIM_Ticket);
+  
   // Then copy nonce
   nonce = 0;
-  if (NULL != nonce_str)
+  if (NULL != nonce_str && strcmp("", nonce_str) != 0)
   {
     if ((1 != SSCANF (nonce_str, "%u", &nonce)) || (nonce > UINT32_MAX))
     {
@@ -447,11 +450,11 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
   nonce_tmp = htonl (nonce);
   memcpy (buf_ptr, &nonce_tmp, sizeof (uint32_t));
   buf_ptr += sizeof (uint32_t);
+  
   // Finally, attributes
   if (NULL != attrs_ser)
   {
     memcpy (buf_ptr, attrs_ser, attr_list_len);
-    buf_ptr += attr_list_len;
     GNUNET_free (attrs_ser);
   }
   // Generate ECDH key
@@ -482,7 +485,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
       GNUNET_CRYPTO_ecdsa_sign (issuer,
                                 purpose,
                                 (struct GNUNET_CRYPTO_EcdsaSignature *)
-                                  buf_ptr))
+                                buf_ptr))
   {
     GNUNET_break (0);
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to sign code\n");
@@ -532,10 +535,10 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
   code_payload_len =
     GNUNET_STRINGS_base64_decode (code, strlen (code), (void **) &code_payload);
   if (code_payload_len < sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
-                           sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) +
-                           sizeof (struct GNUNET_RECLAIM_Ticket) +
-                           sizeof (uint32_t) +
-                           sizeof (struct GNUNET_CRYPTO_EcdsaSignature))
+      sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) +
+      sizeof (struct GNUNET_RECLAIM_Ticket) +
+      sizeof (uint32_t) +
+      sizeof (struct GNUNET_CRYPTO_EcdsaSignature))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Authorization code malformed\n");
     GNUNET_free_non_null (code_payload);