crypto/rsa/rsa_x931g.c:191: error: NULL_DEREFERENCE
  pointer `ctx` last assigned on line 150 could be null and is dereferenced by call to `BN_CTX_free()` at line 191, column 5.
Showing all 24 steps of the trace


crypto/rsa/rsa_x931g.c:143:1: start of procedure RSA_X931_generate_key_ex()
141.   }
142.   
143. > int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
144.                                BN_GENCB *cb)
145.   {

crypto/rsa/rsa_x931g.c:146:5: 
144.                                BN_GENCB *cb)
145.   {
146. >     int ok = 0;
147.       BIGNUM *Xp = NULL, *Xq = NULL;
148.       BN_CTX *ctx = NULL;

crypto/rsa/rsa_x931g.c:147:5: 
145.   {
146.       int ok = 0;
147. >     BIGNUM *Xp = NULL, *Xq = NULL;
148.       BN_CTX *ctx = NULL;
149.   

crypto/rsa/rsa_x931g.c:148:5: 
146.       int ok = 0;
147.       BIGNUM *Xp = NULL, *Xq = NULL;
148. >     BN_CTX *ctx = NULL;
149.   
150.       ctx = BN_CTX_new();

crypto/rsa/rsa_x931g.c:150:5: Skipping BN_CTX_new(): empty list of specs
148.       BN_CTX *ctx = NULL;
149.   
150.       ctx = BN_CTX_new();
           ^
151.       if (ctx == NULL)
152.           goto error;

crypto/rsa/rsa_x931g.c:151:9: Taking true branch
149.   
150.       ctx = BN_CTX_new();
151.       if (ctx == NULL)
               ^
152.           goto error;
153.   

crypto/rsa/rsa_x931g.c:188:2: 
186.       ok = 1;
187.   
188. >  error:
189.       if (ctx)
190.           BN_CTX_end(ctx);

crypto/rsa/rsa_x931g.c:189:9: Taking false branch
187.   
188.    error:
189.       if (ctx)
               ^
190.           BN_CTX_end(ctx);
191.       BN_CTX_free(ctx);

crypto/rsa/rsa_x931g.c:191:5: 
189.       if (ctx)
190.           BN_CTX_end(ctx);
191. >     BN_CTX_free(ctx);
192.   
193.       if (ok)

crypto/bn/bn_ctx.c:157:1: start of procedure BN_CTX_free()
  155.   }
  156.   
  157. > void BN_CTX_free(BN_CTX *ctx)
  158.   {
  159.   #ifdef BN_CTX_DEBUG

crypto/bn/bn_ctx.c:174:5: 
  172.       }
  173.   #endif
  174. >     BN_STACK_finish(&ctx->stack);
  175.       BN_POOL_finish(&ctx->pool);
  176.       OPENSSL_free(ctx);

crypto/bn/bn_ctx.c:243:1: start of procedure BN_STACK_finish()
    241.   }
    242.   
    243. > static void BN_STACK_finish(BN_STACK *st)
    244.   {
    245.       OPENSSL_free(st->indexes);

crypto/bn/bn_ctx.c:245:5: 
    243.   static void BN_STACK_finish(BN_STACK *st)
    244.   {
    245. >     OPENSSL_free(st->indexes);
    246.       st->indexes = NULL;
    247.   }

crypto/mem.c:295:1: start of procedure CRYPTO_free()
      293.   }
      294.   
      295. > void CRYPTO_free(void *str, const char *file, int line)
      296.   {
      297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking true branch
      296.   {
      297.       INCREMENT(free_count);
      298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                     ^
      299.           free_impl(str, file, line);
      300.           return;

crypto/mem.c:298:30: Taking true branch
      296.   {
      297.       INCREMENT(free_count);
      298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                          ^
      299.           free_impl(str, file, line);
      300.           return;

crypto/mem.c:299:9: Skipping __function_pointer__(): unresolved function pointer
      297.       INCREMENT(free_count);
      298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
      299.           free_impl(str, file, line);
                     ^
      300.           return;
      301.       }

crypto/mem.c:300:9: 
      298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
      299.           free_impl(str, file, line);
      300. >         return;
      301.       }
      302.   

crypto/mem.c:314:1: return from a call to CRYPTO_free
      312.       free(str);
      313.   #endif
      314. > }
      315.   
      316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/bn/bn_ctx.c:246:5: 
    244.   {
    245.       OPENSSL_free(st->indexes);
    246. >     st->indexes = NULL;
    247.   }
    248.   

crypto/bn/bn_ctx.c:247:1: return from a call to BN_STACK_finish
    245.       OPENSSL_free(st->indexes);
    246.       st->indexes = NULL;
    247. > }
    248.   
    249.   

crypto/bn/bn_ctx.c:175:5: 
  173.   #endif
  174.       BN_STACK_finish(&ctx->stack);
  175. >     BN_POOL_finish(&ctx->pool);
  176.       OPENSSL_free(ctx);
  177.   }

crypto/bn/bn_ctx.c:284:1: start of procedure BN_POOL_finish()
    282.   }
    283.   
    284. > static void BN_POOL_finish(BN_POOL *p)
    285.   {
    286.       unsigned int loop;

crypto/bn/bn_ctx.c:289:12: Loop condition is false. Leaving loop
    287.       BIGNUM *bn;
    288.   
    289.       while (p->head) {
                      ^
    290.           for (loop = 0, bn = p->head->vals; loop++ < BN_CTX_POOL_SIZE; bn++)
    291.               if (bn->d)

int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
                             BN_GENCB *cb)
{
    int ok = 0;
    BIGNUM *Xp = NULL, *Xq = NULL;
    BN_CTX *ctx = NULL;
    ctx = BN_CTX_new();
    if (ctx == NULL)
        goto error;
    BN_CTX_start(ctx);
    Xp = BN_CTX_get(ctx);
    Xq = BN_CTX_get(ctx);
    if (Xq == NULL)
        goto error;
    if (!BN_X931_generate_Xpq(Xp, Xq, bits, ctx))
        goto error;
    rsa->p = BN_new();
    rsa->q = BN_new();
    if (rsa->p == NULL || rsa->q == NULL)
        goto error;
    if (!BN_X931_generate_prime_ex(rsa->p, NULL, NULL, NULL, NULL, Xp,
                                   e, ctx, cb))
        goto error;
    if (!BN_X931_generate_prime_ex(rsa->q, NULL, NULL, NULL, NULL, Xq,
                                   e, ctx, cb))
        goto error;
    if (!RSA_X931_derive_ex(rsa, NULL, NULL, NULL, NULL,
                            NULL, NULL, NULL, NULL, NULL, NULL, e, cb))
        goto error;
    ok = 1;
 error:
    if (ctx)
        BN_CTX_end(ctx);
    BN_CTX_free(ctx);
    if (ok)
        return 1;
    return 0;
}
['int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,\n                             BN_GENCB *cb)\n{\n    int ok = 0;\n    BIGNUM *Xp = NULL, *Xq = NULL;\n    BN_CTX *ctx = NULL;\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        goto error;\n    BN_CTX_start(ctx);\n    Xp = BN_CTX_get(ctx);\n    Xq = BN_CTX_get(ctx);\n    if (Xq == NULL)\n        goto error;\n    if (!BN_X931_generate_Xpq(Xp, Xq, bits, ctx))\n        goto error;\n    rsa->p = BN_new();\n    rsa->q = BN_new();\n    if (rsa->p == NULL || rsa->q == NULL)\n        goto error;\n    if (!BN_X931_generate_prime_ex(rsa->p, NULL, NULL, NULL, NULL, Xp,\n                                   e, ctx, cb))\n        goto error;\n    if (!BN_X931_generate_prime_ex(rsa->q, NULL, NULL, NULL, NULL, Xq,\n                                   e, ctx, cb))\n        goto error;\n    if (!RSA_X931_derive_ex(rsa, NULL, NULL, NULL, NULL,\n                            NULL, NULL, NULL, NULL, NULL, NULL, e, cb))\n        goto error;\n    ok = 1;\n error:\n    if (ctx)\n        BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    if (ok)\n        return 1;\n    return 0;\n}', 'void BN_CTX_free(BN_CTX *ctx)\n{\n#ifdef BN_CTX_DEBUG\n    {\n        BN_POOL_ITEM *pool = ctx->pool.head;\n        fprintf(stderr, "BN_CTX_free, stack-size=%d, pool-bignums=%d\\n",\n                ctx->stack.size, ctx->pool.size);\n        fprintf(stderr, "dmaxs: ");\n        while (pool) {\n            unsigned loop = 0;\n            while (loop < BN_CTX_POOL_SIZE)\n                fprintf(stderr, "%02x ", pool->vals[loop++].dmax);\n            pool = pool->next;\n        }\n        fprintf(stderr, "\\n");\n    }\n#endif\n    BN_STACK_finish(&ctx->stack);\n    BN_POOL_finish(&ctx->pool);\n    OPENSSL_free(ctx);\n}', 'static void BN_STACK_finish(BN_STACK *st)\n{\n    OPENSSL_free(st->indexes);\n    st->indexes = NULL;\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n    INCREMENT(free_count);\n    if (free_impl != NULL && free_impl != &CRYPTO_free) {\n        free_impl(str, file, line);\n        return;\n    }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0, file, line);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1, file, line);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}', 'static void BN_POOL_finish(BN_POOL *p)\n{\n    unsigned int loop;\n    BIGNUM *bn;\n    while (p->head) {\n        for (loop = 0, bn = p->head->vals; loop++ < BN_CTX_POOL_SIZE; bn++)\n            if (bn->d)\n                BN_clear_free(bn);\n        p->current = p->head->next;\n        OPENSSL_free(p->head);\n        p->head = p->current;\n    }\n}']