crypto/srp/srp_vfy.c:538: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 523, column 12 is not reachable after line 538, column 5.
Showing all 67 steps of the trace


crypto/srp/srp_vfy.c:494:1: start of procedure SRP_VBASE_get1_by_user()
492.    * In other words, caller must free the result once done.
493.    */
494. > SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username)
495.   {
496.       SRP_user_pwd *user;

crypto/srp/srp_vfy.c:499:5: 
497.       unsigned char digv[SHA_DIGEST_LENGTH];
498.       unsigned char digs[SHA_DIGEST_LENGTH];
499. >     EVP_MD_CTX *ctxt = NULL;
500.   
501.       if (vb == NULL)

crypto/srp/srp_vfy.c:501:9: Taking false branch
499.       EVP_MD_CTX *ctxt = NULL;
500.   
501.       if (vb == NULL)
               ^
502.           return NULL;
503.   

crypto/srp/srp_vfy.c:504:9: 
502.           return NULL;
503.   
504. >     if ((user = find_user(vb, username)) != NULL)
505.           return srp_user_pwd_dup(user);
506.   

crypto/srp/srp_vfy.c:460:1: start of procedure find_user()
  458.   }
  459.   
  460. > static SRP_user_pwd *find_user(SRP_VBASE *vb, char *username)
  461.   {
  462.       int i;

crypto/srp/srp_vfy.c:465:9: Taking false branch
  463.       SRP_user_pwd *user;
  464.   
  465.       if (vb == NULL)
                 ^
  466.           return NULL;
  467.   

crypto/srp/srp_vfy.c:468:10: 
  466.           return NULL;
  467.   
  468. >     for (i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++) {
  469.           user = sk_SRP_user_pwd_value(vb->users_pwd, i);
  470.           if (strcmp(user->id, username) == 0)

crypto/srp/srp_vfy.c:468:17: 
  466.           return NULL;
  467.   
  468. >     for (i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++) {
  469.           user = sk_SRP_user_pwd_value(vb->users_pwd, i);
  470.           if (strcmp(user->id, username) == 0)

include/openssl/srp.h:48:1: start of procedure sk_SRP_user_pwd_num()
    46.   void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
    47.   
    48. > DEFINE_STACK_OF(SRP_user_pwd)
    49.   
    50.   typedef struct SRP_VBASE_st {

crypto/stack/stack.c:277:1: start of procedure OPENSSL_sk_num()
      275.   }
      276.   
      277. > int OPENSSL_sk_num(const OPENSSL_STACK *st)
      278.   {
      279.       if (st == NULL)

crypto/stack/stack.c:279:9: Taking true branch
      277.   int OPENSSL_sk_num(const OPENSSL_STACK *st)
      278.   {
      279.       if (st == NULL)
                     ^
      280.           return -1;
      281.       return st->num;

crypto/stack/stack.c:280:9: 
      278.   {
      279.       if (st == NULL)
      280. >         return -1;
      281.       return st->num;
      282.   }

crypto/stack/stack.c:282:1: return from a call to OPENSSL_sk_num
      280.           return -1;
      281.       return st->num;
      282. > }
      283.   
      284.   void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)

include/openssl/srp.h:48:1: return from a call to sk_SRP_user_pwd_num
    46.   void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
    47.   
    48. > DEFINE_STACK_OF(SRP_user_pwd)
    49.   
    50.   typedef struct SRP_VBASE_st {

crypto/srp/srp_vfy.c:468:17: Loop condition is false. Leaving loop
  466.           return NULL;
  467.   
  468.       for (i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++) {
                         ^
  469.           user = sk_SRP_user_pwd_value(vb->users_pwd, i);
  470.           if (strcmp(user->id, username) == 0)

crypto/srp/srp_vfy.c:474:5: 
  472.       }
  473.   
  474. >     return NULL;
  475.   }
  476.   

crypto/srp/srp_vfy.c:475:1: return from a call to find_user
  473.   
  474.       return NULL;
  475. > }
  476.   
  477.   # if OPENSSL_API_COMPAT < 0x10100000L

crypto/srp/srp_vfy.c:504:9: Taking false branch
502.           return NULL;
503.   
504.       if ((user = find_user(vb, username)) != NULL)
               ^
505.           return srp_user_pwd_dup(user);
506.   

crypto/srp/srp_vfy.c:507:10: Taking false branch
505.           return srp_user_pwd_dup(user);
506.   
507.       if ((vb->seed_key == NULL) ||
                ^
508.           (vb->default_g == NULL) || (vb->default_N == NULL))
509.           return NULL;

crypto/srp/srp_vfy.c:508:10: Taking false branch
506.   
507.       if ((vb->seed_key == NULL) ||
508.           (vb->default_g == NULL) || (vb->default_N == NULL))
                ^
509.           return NULL;
510.   

crypto/srp/srp_vfy.c:508:37: Taking false branch
506.   
507.       if ((vb->seed_key == NULL) ||
508.           (vb->default_g == NULL) || (vb->default_N == NULL))
                                           ^
509.           return NULL;
510.   

crypto/srp/srp_vfy.c:513:9: Taking false branch
511.   /* if the user is unknown we set parameters as well if we have a seed_key */
512.   
513.       if ((user = SRP_user_pwd_new()) == NULL)
               ^
514.           return NULL;
515.   

crypto/srp/srp_vfy.c:516:5: 
514.           return NULL;
515.   
516. >     SRP_user_pwd_set_gN(user, vb->default_g, vb->default_N);
517.   
518.       if (!SRP_user_pwd_set_ids(user, username, NULL))

crypto/srp/srp_vfy.c:169:1: start of procedure SRP_user_pwd_set_gN()
  167.   }
  168.   
  169. > static void SRP_user_pwd_set_gN(SRP_user_pwd *vinfo, const BIGNUM *g,
  170.                                   const BIGNUM *N)
  171.   {

crypto/srp/srp_vfy.c:172:5: 
  170.                                   const BIGNUM *N)
  171.   {
  172. >     vinfo->N = N;
  173.       vinfo->g = g;
  174.   }

crypto/srp/srp_vfy.c:173:5: 
  171.   {
  172.       vinfo->N = N;
  173. >     vinfo->g = g;
  174.   }
  175.   

crypto/srp/srp_vfy.c:174:1: return from a call to SRP_user_pwd_set_gN
  172.       vinfo->N = N;
  173.       vinfo->g = g;
  174. > }
  175.   
  176.   static int SRP_user_pwd_set_ids(SRP_user_pwd *vinfo, const char *id,

crypto/srp/srp_vfy.c:518:10: Taking false branch
516.       SRP_user_pwd_set_gN(user, vb->default_g, vb->default_N);
517.   
518.       if (!SRP_user_pwd_set_ids(user, username, NULL))
                ^
519.           goto err;
520.   

crypto/srp/srp_vfy.c:521:9: Taking false branch
519.           goto err;
520.   
521.       if (RAND_bytes(digv, SHA_DIGEST_LENGTH) <= 0)
               ^
522.           goto err;
523.       ctxt = EVP_MD_CTX_new();

crypto/srp/srp_vfy.c:523:5: 
521.       if (RAND_bytes(digv, SHA_DIGEST_LENGTH) <= 0)
522.           goto err;
523. >     ctxt = EVP_MD_CTX_new();
524.       if (ctxt == NULL
525.           || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)

crypto/evp/digest.c:44:1: start of procedure EVP_MD_CTX_new()
  42.   }
  43.   
  44. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:46:5: 
  44.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47.   }
  48.   

crypto/mem.c:197:1: start of procedure CRYPTO_zalloc()
    195.   }
    196.   
    197. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    198.   {
    199.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:199:5: 
    197.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    198.   {
    199. >     void *ret = CRYPTO_malloc(num, file, line);
    200.   
    201.       FAILTEST();

crypto/mem.c:169:1: start of procedure CRYPTO_malloc()
      167.   #endif
      168.   
      169. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      170.   {
      171.       void *ret = NULL;

crypto/mem.c:171:5: 
      169.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      170.   {
      171. >     void *ret = NULL;
      172.   
      173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:173:9: Taking false branch
      171.       void *ret = NULL;
      172.   
      173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      174.           return malloc_impl(num, file, line);
      175.   

crypto/mem.c:176:9: Taking false branch
      174.           return malloc_impl(num, file, line);
      175.   
      176.       if (num == 0)
                     ^
      177.           return NULL;
      178.   

crypto/mem.c:180:5: 
      178.   
      179.       FAILTEST();
      180. >     allow_customize = 0;
      181.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      182.       if (call_malloc_debug) {

crypto/mem.c:190:5: 
      188.       }
      189.   #else
      190. >     osslargused(file); osslargused(line);
      191.       ret = malloc(num);
      192.   #endif

crypto/mem.c:190:24: 
      188.       }
      189.   #else
      190. >     osslargused(file); osslargused(line);
      191.       ret = malloc(num);
      192.   #endif

crypto/mem.c:191:5: 
      189.   #else
      190.       osslargused(file); osslargused(line);
      191. >     ret = malloc(num);
      192.   #endif
      193.   

crypto/mem.c:194:5: 
      192.   #endif
      193.   
      194. >     return ret;
      195.   }
      196.   

crypto/mem.c:195:1: return from a call to CRYPTO_malloc
      193.   
      194.       return ret;
      195. > }
      196.   
      197.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:202:9: Taking true branch
    200.   
    201.       FAILTEST();
    202.       if (ret != NULL)
                   ^
    203.           memset(ret, 0, num);
    204.       return ret;

crypto/mem.c:203:9: 
    201.       FAILTEST();
    202.       if (ret != NULL)
    203. >         memset(ret, 0, num);
    204.       return ret;
    205.   }

crypto/mem.c:204:5: 
    202.       if (ret != NULL)
    203.           memset(ret, 0, num);
    204. >     return ret;
    205.   }
    206.   

crypto/mem.c:205:1: return from a call to CRYPTO_zalloc
    203.           memset(ret, 0, num);
    204.       return ret;
    205. > }
    206.   
    207.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:47:1: return from a call to EVP_MD_CTX_new
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47. > }
  48.   
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

crypto/srp/srp_vfy.c:524:9: Taking false branch
522.           goto err;
523.       ctxt = EVP_MD_CTX_new();
524.       if (ctxt == NULL
               ^
525.           || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
526.           || !EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key))

crypto/srp/srp_vfy.c:525:13: 
523.       ctxt = EVP_MD_CTX_new();
524.       if (ctxt == NULL
525. >         || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
526.           || !EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key))
527.           || !EVP_DigestUpdate(ctxt, username, strlen(username))

crypto/evp/m_sha1.c:108:1: start of procedure EVP_sha1()
  106.   };
  107.   
  108. > const EVP_MD *EVP_sha1(void)
  109.   {
  110.       return (&sha1_md);

crypto/evp/m_sha1.c:110:5: 
  108.   const EVP_MD *EVP_sha1(void)
  109.   {
  110. >     return (&sha1_md);
  111.   }
  112.   

crypto/evp/m_sha1.c:111:1: return from a call to EVP_sha1
  109.   {
  110.       return (&sha1_md);
  111. > }
  112.   
  113.   static int init224(EVP_MD_CTX *ctx)

crypto/srp/srp_vfy.c:525:13: Taking true branch
523.       ctxt = EVP_MD_CTX_new();
524.       if (ctxt == NULL
525.           || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
                   ^
526.           || !EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key))
527.           || !EVP_DigestUpdate(ctxt, username, strlen(username))

crypto/srp/srp_vfy.c:537:2: 
535.           return user;
536.   
537. >  err:
538.       EVP_MD_CTX_free(ctxt);
539.       SRP_user_pwd_free(user);

crypto/srp/srp_vfy.c:538:5: 
536.   
537.    err:
538. >     EVP_MD_CTX_free(ctxt);
539.       SRP_user_pwd_free(user);
540.       return NULL;

crypto/evp/digest.c:49:1: start of procedure EVP_MD_CTX_free()
  47.   }
  48.   
  49. > void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);

crypto/evp/digest.c:51:5: Skipping EVP_MD_CTX_reset(): empty list of specs
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
            ^
  52.       OPENSSL_free(ctx);
  53.   }

crypto/evp/digest.c:52:5: 
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
  52. >     OPENSSL_free(ctx);
  53.   }
  54.   

crypto/mem.c:264:1: start of procedure CRYPTO_free()
    262.   }
    263.   
    264. > void CRYPTO_free(void *str, const char *file, int line)
    265.   {
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:266:9: Taking true branch
    264.   void CRYPTO_free(void *str, const char *file, int line)
    265.   {
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    267.           free_impl(str, file, line);
    268.           return;

crypto/mem.c:266:30: Taking true branch
    264.   void CRYPTO_free(void *str, const char *file, int line)
    265.   {
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    267.           free_impl(str, file, line);
    268.           return;

crypto/mem.c:267:9: Skipping __function_pointer__(): unresolved function pointer
    265.   {
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    267.           free_impl(str, file, line);
                   ^
    268.           return;
    269.       }

crypto/mem.c:268:9: 
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    267.           free_impl(str, file, line);
    268. >         return;
    269.       }
    270.   

crypto/mem.c:282:1: return from a call to CRYPTO_free
    280.       free(str);
    281.   #endif
    282. > }
    283.   
    284.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:53:1: return from a call to EVP_MD_CTX_free
  51.       EVP_MD_CTX_reset(ctx);
  52.       OPENSSL_free(ctx);
  53. > }
  54.   
  55.   int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)

SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username)
{
    SRP_user_pwd *user;
    unsigned char digv[SHA_DIGEST_LENGTH];
    unsigned char digs[SHA_DIGEST_LENGTH];
    EVP_MD_CTX *ctxt = NULL;
    if (vb == NULL)
        return NULL;
    if ((user = find_user(vb, username)) != NULL)
        return srp_user_pwd_dup(user);
    if ((vb->seed_key == NULL) ||
        (vb->default_g == NULL) || (vb->default_N == NULL))
        return NULL;
    if ((user = SRP_user_pwd_new()) == NULL)
        return NULL;
    SRP_user_pwd_set_gN(user, vb->default_g, vb->default_N);
    if (!SRP_user_pwd_set_ids(user, username, NULL))
        goto err;
    if (RAND_bytes(digv, SHA_DIGEST_LENGTH) <= 0)
        goto err;
    ctxt = EVP_MD_CTX_new();
    if (ctxt == NULL
        || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
        || !EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key))
        || !EVP_DigestUpdate(ctxt, username, strlen(username))
        || !EVP_DigestFinal_ex(ctxt, digs, NULL))
        goto err;
    EVP_MD_CTX_free(ctxt);
    ctxt = NULL;
    if (SRP_user_pwd_set_sv_BN(user,
                               BN_bin2bn(digs, SHA_DIGEST_LENGTH, NULL),
                               BN_bin2bn(digv, SHA_DIGEST_LENGTH, NULL)))
        return user;
 err:
    EVP_MD_CTX_free(ctxt);
    SRP_user_pwd_free(user);
    return NULL;
}
['SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username)\n{\n    SRP_user_pwd *user;\n    unsigned char digv[SHA_DIGEST_LENGTH];\n    unsigned char digs[SHA_DIGEST_LENGTH];\n    EVP_MD_CTX *ctxt = NULL;\n    if (vb == NULL)\n        return NULL;\n    if ((user = find_user(vb, username)) != NULL)\n        return srp_user_pwd_dup(user);\n    if ((vb->seed_key == NULL) ||\n        (vb->default_g == NULL) || (vb->default_N == NULL))\n        return NULL;\n    if ((user = SRP_user_pwd_new()) == NULL)\n        return NULL;\n    SRP_user_pwd_set_gN(user, vb->default_g, vb->default_N);\n    if (!SRP_user_pwd_set_ids(user, username, NULL))\n        goto err;\n    if (RAND_bytes(digv, SHA_DIGEST_LENGTH) <= 0)\n        goto err;\n    ctxt = EVP_MD_CTX_new();\n    if (ctxt == NULL\n        || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)\n        || !EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key))\n        || !EVP_DigestUpdate(ctxt, username, strlen(username))\n        || !EVP_DigestFinal_ex(ctxt, digs, NULL))\n        goto err;\n    EVP_MD_CTX_free(ctxt);\n    ctxt = NULL;\n    if (SRP_user_pwd_set_sv_BN(user,\n                               BN_bin2bn(digs, SHA_DIGEST_LENGTH, NULL),\n                               BN_bin2bn(digv, SHA_DIGEST_LENGTH, NULL)))\n        return user;\n err:\n    EVP_MD_CTX_free(ctxt);\n    SRP_user_pwd_free(user);\n    return NULL;\n}', 'static SRP_user_pwd *find_user(SRP_VBASE *vb, char *username)\n{\n    int i;\n    SRP_user_pwd *user;\n    if (vb == NULL)\n        return NULL;\n    for (i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++) {\n        user = sk_SRP_user_pwd_value(vb->users_pwd, i);\n        if (strcmp(user->id, username) == 0)\n            return user;\n    }\n    return NULL;\n}', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n    if (st == NULL)\n        return -1;\n    return st->num;\n}', 'static void SRP_user_pwd_set_gN(SRP_user_pwd *vinfo, const BIGNUM *g,\n                                const BIGNUM *N)\n{\n    vinfo->N = N;\n    vinfo->g = g;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'const EVP_MD *EVP_sha1(void)\n{\n    return (&sha1_md);\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n    EVP_MD_CTX_reset(ctx);\n    OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\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}']