RT4313: Fix build for !IMPLEMENTED code path in CRYPTO_secure_free()
[openssl.git] / crypto / jpake / jpake.c
index eb6654d44fe683066b4f9e49735f2d7a9b4034c7..abbcb89a2aed9f1fdbbecf0918e22fcedec815f9 100644 (file)
@@ -107,14 +107,14 @@ static void JPAKE_CTX_release(JPAKE_CTX *ctx)
     OPENSSL_free(ctx->p.peer_name);
     OPENSSL_free(ctx->p.name);
 
-    memset(ctx, '\0', sizeof *ctx);
+    memset(ctx, 0, sizeof(*ctx));
 }
 
 JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name,
                          const BIGNUM *p, const BIGNUM *g, const BIGNUM *q,
                          const BIGNUM *secret)
 {
-    JPAKE_CTX *ctx = OPENSSL_malloc(sizeof *ctx);
+    JPAKE_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
     if (ctx == NULL)
         return NULL;
 
@@ -125,6 +125,8 @@ JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name,
 
 void JPAKE_CTX_free(JPAKE_CTX *ctx)
 {
+    if (!ctx)
+        return;
     JPAKE_CTX_release(ctx);
     OPENSSL_free(ctx);
 }
@@ -199,6 +201,9 @@ static int generate_zkp(JPAKE_STEP_PART *p, const BIGNUM *x,
     BIGNUM *h = BN_new();
     BIGNUM *t = BN_new();
 
+    if (r == NULL || h == NULL || t == NULL)
+        goto end;
+
    /*-
     * r in [0,q)
     * XXX: Java chooses r in [0, 2^160) - i.e. distribution not uniform
@@ -233,6 +238,9 @@ static int verify_zkp(const JPAKE_STEP_PART *p, const BIGNUM *zkpg,
     BIGNUM *t3 = BN_new();
     int ret = 0;
 
+    if (h == NULL || t1 == NULL || t2 == NULL || t3 == NULL)
+        goto end;
+
     if (!zkp_hash(h, zkpg, p, ctx->p.peer_name))
         goto end;