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


crypto/srp/srp_vfy.c:394:1: start of procedure SRP_VBASE_get1_by_user()
392.    * In other words, caller must free the result once done.
393.    */
394. > SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username)
395.   {
396.       SRP_user_pwd *user;

crypto/srp/srp_vfy.c:399:5: 
397.       unsigned char digv[SHA_DIGEST_LENGTH];
398.       unsigned char digs[SHA_DIGEST_LENGTH];
399. >     EVP_MD_CTX *ctxt = NULL;
400.   
401.       if (vb == NULL)

crypto/srp/srp_vfy.c:401:9: Taking false branch
399.       EVP_MD_CTX *ctxt = NULL;
400.   
401.       if (vb == NULL)
               ^
402.           return NULL;
403.   

crypto/srp/srp_vfy.c:404:9: 
402.           return NULL;
403.   
404. >     if ((user = find_user(vb, username)) != NULL)
405.           return srp_user_pwd_dup(user);
406.   

crypto/srp/srp_vfy.c:360:1: start of procedure find_user()
  358.   }
  359.   
  360. > static SRP_user_pwd *find_user(SRP_VBASE *vb, char *username)
  361.   {
  362.       int i;

crypto/srp/srp_vfy.c:365:9: Taking false branch
  363.       SRP_user_pwd *user;
  364.   
  365.       if (vb == NULL)
                 ^
  366.           return NULL;
  367.   

crypto/srp/srp_vfy.c:368:10: 
  366.           return NULL;
  367.   
  368. >     for (i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++) {
  369.           user = sk_SRP_user_pwd_value(vb->users_pwd, i);
  370.           if (strcmp(user->id, username) == 0)

crypto/srp/srp_vfy.c:368:17: 
  366.           return NULL;
  367.   
  368. >     for (i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++) {
  369.           user = sk_SRP_user_pwd_value(vb->users_pwd, i);
  370.           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:375:1: start of procedure OPENSSL_sk_num()
      373.   }
      374.   
      375. > int OPENSSL_sk_num(const OPENSSL_STACK *st)
      376.   {
      377.       return st == NULL ? -1 : st->num;

crypto/stack/stack.c:377:12: Condition is true
      375.   int OPENSSL_sk_num(const OPENSSL_STACK *st)
      376.   {
      377.       return st == NULL ? -1 : st->num;
                        ^
      378.   }
      379.   

crypto/stack/stack.c:377:5: 
      375.   int OPENSSL_sk_num(const OPENSSL_STACK *st)
      376.   {
      377. >     return st == NULL ? -1 : st->num;
      378.   }
      379.   

crypto/stack/stack.c:378:1: return from a call to OPENSSL_sk_num
      376.   {
      377.       return st == NULL ? -1 : st->num;
      378. > }
      379.   
      380.   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:368:17: Loop condition is false. Leaving loop
  366.           return NULL;
  367.   
  368.       for (i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++) {
                         ^
  369.           user = sk_SRP_user_pwd_value(vb->users_pwd, i);
  370.           if (strcmp(user->id, username) == 0)

crypto/srp/srp_vfy.c:374:5: 
  372.       }
  373.   
  374. >     return NULL;
  375.   }
  376.   

crypto/srp/srp_vfy.c:375:1: return from a call to find_user
  373.   
  374.       return NULL;
  375. > }
  376.   
  377.   # if OPENSSL_API_COMPAT < 0x10100000L

crypto/srp/srp_vfy.c:404:9: Taking false branch
402.           return NULL;
403.   
404.       if ((user = find_user(vb, username)) != NULL)
               ^
405.           return srp_user_pwd_dup(user);
406.   

crypto/srp/srp_vfy.c:407:10: Taking false branch
405.           return srp_user_pwd_dup(user);
406.   
407.       if ((vb->seed_key == NULL) ||
                ^
408.           (vb->default_g == NULL) || (vb->default_N == NULL))
409.           return NULL;

crypto/srp/srp_vfy.c:408:10: Taking false branch
406.   
407.       if ((vb->seed_key == NULL) ||
408.           (vb->default_g == NULL) || (vb->default_N == NULL))
                ^
409.           return NULL;
410.   

crypto/srp/srp_vfy.c:408:37: Taking false branch
406.   
407.       if ((vb->seed_key == NULL) ||
408.           (vb->default_g == NULL) || (vb->default_N == NULL))
                                           ^
409.           return NULL;
410.   

crypto/srp/srp_vfy.c:413:9: Taking false branch
411.   /* if the user is unknown we set parameters as well if we have a seed_key */
412.   
413.       if ((user = SRP_user_pwd_new()) == NULL)
               ^
414.           return NULL;
415.   

crypto/srp/srp_vfy.c:416:5: 
414.           return NULL;
415.   
416. >     SRP_user_pwd_set_gN(user, vb->default_g, vb->default_N);
417.   
418.       if (!SRP_user_pwd_set_ids(user, username, NULL))

crypto/srp/srp_vfy.c:69:1: start of procedure SRP_user_pwd_set_gN()
  67.   }
  68.   
  69. > static void SRP_user_pwd_set_gN(SRP_user_pwd *vinfo, const BIGNUM *g,
  70.                                   const BIGNUM *N)
  71.   {

crypto/srp/srp_vfy.c:72:5: 
  70.                                   const BIGNUM *N)
  71.   {
  72. >     vinfo->N = N;
  73.       vinfo->g = g;
  74.   }

crypto/srp/srp_vfy.c:73:5: 
  71.   {
  72.       vinfo->N = N;
  73. >     vinfo->g = g;
  74.   }
  75.   

crypto/srp/srp_vfy.c:74:1: return from a call to SRP_user_pwd_set_gN
  72.       vinfo->N = N;
  73.       vinfo->g = g;
  74. > }
  75.   
  76.   static int SRP_user_pwd_set_ids(SRP_user_pwd *vinfo, const char *id,

crypto/srp/srp_vfy.c:418:10: Taking false branch
416.       SRP_user_pwd_set_gN(user, vb->default_g, vb->default_N);
417.   
418.       if (!SRP_user_pwd_set_ids(user, username, NULL))
                ^
419.           goto err;
420.   

crypto/srp/srp_vfy.c:421:9: Taking false branch
419.           goto err;
420.   
421.       if (RAND_bytes(digv, SHA_DIGEST_LENGTH) <= 0)
               ^
422.           goto err;
423.       ctxt = EVP_MD_CTX_new();

crypto/srp/srp_vfy.c:423:5: 
421.       if (RAND_bytes(digv, SHA_DIGEST_LENGTH) <= 0)
422.           goto err;
423. >     ctxt = EVP_MD_CTX_new();
424.       if (ctxt == NULL
425.           || !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:228:1: start of procedure CRYPTO_zalloc()
    226.   }
    227.   
    228. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:230:5: 
    228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230. >     void *ret = CRYPTO_malloc(num, file, line);
    231.   
    232.       FAILTEST();

crypto/mem.c:192:1: start of procedure CRYPTO_malloc()
      190.   #endif
      191.   
      192. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194.       void *ret = NULL;

crypto/mem.c:194:5: 
      192.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194. >     void *ret = NULL;
      195.   
      196.       INCREMENT(malloc_count);

crypto/mem.c:197:9: Taking false branch
      195.   
      196.       INCREMENT(malloc_count);
      197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      198.           return malloc_impl(num, file, line);
      199.   

crypto/mem.c:200:9: Taking false branch
      198.           return malloc_impl(num, file, line);
      199.   
      200.       if (num == 0)
                     ^
      201.           return NULL;
      202.   

crypto/mem.c:204:9: Taking true branch
      202.   
      203.       FAILTEST();
      204.       if (allow_customize) {
                     ^
      205.           /*
      206.            * Disallow customization after the first allocation. We only set this

crypto/mem.c:210:9: 
      208.            * allocation.
      209.            */
      210. >         allow_customize = 0;
      211.       }
      212.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

crypto/mem.c:221:5: 
      219.       }
      220.   #else
      221. >     (void)(file); (void)(line);
      222.       ret = malloc(num);
      223.   #endif

crypto/mem.c:221:19: 
      219.       }
      220.   #else
      221. >     (void)(file); (void)(line);
      222.       ret = malloc(num);
      223.   #endif

crypto/mem.c:222:5: 
      220.   #else
      221.       (void)(file); (void)(line);
      222. >     ret = malloc(num);
      223.   #endif
      224.   

crypto/mem.c:225:5: 
      223.   #endif
      224.   
      225. >     return ret;
      226.   }
      227.   

crypto/mem.c:226:1: return from a call to CRYPTO_malloc
      224.   
      225.       return ret;
      226. > }
      227.   
      228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:233:9: Taking true branch
    231.   
    232.       FAILTEST();
    233.       if (ret != NULL)
                   ^
    234.           memset(ret, 0, num);
    235.       return ret;

crypto/mem.c:234:9: 
    232.       FAILTEST();
    233.       if (ret != NULL)
    234. >         memset(ret, 0, num);
    235.       return ret;
    236.   }

crypto/mem.c:235:5: 
    233.       if (ret != NULL)
    234.           memset(ret, 0, num);
    235. >     return ret;
    236.   }
    237.   

crypto/mem.c:236:1: return from a call to CRYPTO_zalloc
    234.           memset(ret, 0, num);
    235.       return ret;
    236. > }
    237.   
    238.   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:424:9: Taking false branch
422.           goto err;
423.       ctxt = EVP_MD_CTX_new();
424.       if (ctxt == NULL
               ^
425.           || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
426.           || !EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key))

crypto/srp/srp_vfy.c:425:13: 
423.       ctxt = EVP_MD_CTX_new();
424.       if (ctxt == NULL
425. >         || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
426.           || !EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key))
427.           || !EVP_DigestUpdate(ctxt, username, strlen(username))

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

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

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

crypto/srp/srp_vfy.c:425:13: Taking true branch
423.       ctxt = EVP_MD_CTX_new();
424.       if (ctxt == NULL
425.           || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
                   ^
426.           || !EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key))
427.           || !EVP_DigestUpdate(ctxt, username, strlen(username))

crypto/srp/srp_vfy.c:437:2: 
435.           return user;
436.   
437. >  err:
438.       EVP_MD_CTX_free(ctxt);
439.       SRP_user_pwd_free(user);

crypto/srp/srp_vfy.c:438:5: 
436.   
437.    err:
438. >     EVP_MD_CTX_free(ctxt);
439.       SRP_user_pwd_free(user);
440.       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: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/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    return st == NULL ? -1 : 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    INCREMENT(malloc_count);\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    if (allow_customize) {\n        allow_customize = 0;\n    }\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    (void)(file); (void)(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    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}']