Memory leak fix: RSA_blinding_on() didn't free Ai under certain circumstances.
authorRichard Levitte <levitte@openssl.org>
Wed, 16 Apr 2003 06:25:21 +0000 (06:25 +0000)
committerRichard Levitte <levitte@openssl.org>
Wed, 16 Apr 2003 06:25:21 +0000 (06:25 +0000)
Memory leak fix: RSA_blinding_on() would leave a dangling pointer in
                 rsa->blinding under certain circumstances.
Double definition fix: RSA_FLAG_NO_BLINDING was defined twice.

crypto/rsa/rsa.h
crypto/rsa/rsa_lib.c

index 604fc26442740a93729275bc0831851acc18b633..12689fc22dd5b2fac339cabaf72f9fe27809119e 100644 (file)
@@ -162,11 +162,6 @@ struct rsa_st
 #define RSA_FLAG_CACHE_PUBLIC          0x02
 #define RSA_FLAG_CACHE_PRIVATE         0x04
 #define RSA_FLAG_BLINDING              0x08
 #define RSA_FLAG_CACHE_PUBLIC          0x02
 #define RSA_FLAG_CACHE_PRIVATE         0x04
 #define RSA_FLAG_BLINDING              0x08
-#define RSA_FLAG_NO_BLINDING           0x80 /* new with 0.9.6j and 0.9.7b; the built-in
-                                              * RSA implementation now uses blinding by
-                                              * default (ignoring RSA_FLAG_BLINDING),
-                                              * but other engines might not need it
-                                              */
 #define RSA_FLAG_THREAD_SAFE           0x10
 /* This flag means the private key operations will be handled by rsa_mod_exp
  * and that they do not depend on the private key components being present:
 #define RSA_FLAG_THREAD_SAFE           0x10
 /* This flag means the private key operations will be handled by rsa_mod_exp
  * and that they do not depend on the private key components being present:
@@ -179,7 +174,11 @@ struct rsa_st
  */
 #define RSA_FLAG_SIGN_VER              0x40
 
  */
 #define RSA_FLAG_SIGN_VER              0x40
 
-#define RSA_FLAG_NO_BLINDING           0x80
+#define RSA_FLAG_NO_BLINDING           0x80 /* new with 0.9.6j and 0.9.7b; the built-in
+                                              * RSA implementation now uses blinding by
+                                              * default (ignoring RSA_FLAG_BLINDING),
+                                              * but other engines might not need it
+                                              */
 
 #define RSA_PKCS1_PADDING      1
 #define RSA_SSLV23_PADDING     2
 
 #define RSA_PKCS1_PADDING      1
 #define RSA_SSLV23_PADDING     2
index 53c5092014befdd6f45b17051248b98618b14658..e4d622851eed84b1e9d4ec76e36e6db76f12a1cb 100644 (file)
@@ -316,7 +316,7 @@ void RSA_blinding_off(RSA *rsa)
 
 int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
        {
 
 int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
        {
-       BIGNUM *A,*Ai;
+       BIGNUM *A,*Ai = NULL;
        BN_CTX *ctx;
        int ret=0;
 
        BN_CTX *ctx;
        int ret=0;
 
@@ -327,8 +327,12 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
        else
                ctx=p_ctx;
 
        else
                ctx=p_ctx;
 
+       /* XXXXX: Shouldn't this be RSA_blinding_off(rsa)? */
        if (rsa->blinding != NULL)
        if (rsa->blinding != NULL)
+               {
                BN_BLINDING_free(rsa->blinding);
                BN_BLINDING_free(rsa->blinding);
+               rsa->blinding = NULL;
+               }
 
        /* NB: similar code appears in setup_blinding (rsa_eay.c);
         * this should be placed in a new function of its own, but for reasons
 
        /* NB: similar code appears in setup_blinding (rsa_eay.c);
         * this should be placed in a new function of its own, but for reasons
@@ -356,9 +360,9 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
        rsa->blinding->thread_id = CRYPTO_thread_id();
        rsa->flags |= RSA_FLAG_BLINDING;
        rsa->flags &= ~RSA_FLAG_NO_BLINDING;
        rsa->blinding->thread_id = CRYPTO_thread_id();
        rsa->flags |= RSA_FLAG_BLINDING;
        rsa->flags &= ~RSA_FLAG_NO_BLINDING;
-       BN_free(Ai);
        ret=1;
 err:
        ret=1;
 err:
+       if (Ai != NULL) BN_free(Ai);
        BN_CTX_end(ctx);
        if (ctx != p_ctx) BN_CTX_free(ctx);
        return(ret);
        BN_CTX_end(ctx);
        if (ctx != p_ctx) BN_CTX_free(ctx);
        return(ret);