test/ssl_test_ctx.c:803: error: NULL_DEREFERENCE
  pointer `ctx` last assigned on line 747 could be null and is dereferenced by call to `SSL_TEST_CTX_free()` at line 803, column 5.
Showing all 50 steps of the trace


test/ssl_test_ctx.c:744:1: start of procedure SSL_TEST_CTX_create()
742.   }
743.   
744. > SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section)
745.   {
746.       STACK_OF(CONF_VALUE) *sk_conf = NULL;

test/ssl_test_ctx.c:746:5: 
744.   SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section)
745.   {
746. >     STACK_OF(CONF_VALUE) *sk_conf = NULL;
747.       SSL_TEST_CTX *ctx = NULL;
748.       int i;

test/ssl_test_ctx.c:747:5: 
745.   {
746.       STACK_OF(CONF_VALUE) *sk_conf = NULL;
747. >     SSL_TEST_CTX *ctx = NULL;
748.       int i;
749.       size_t j;

test/ssl_test_ctx.c:751:10: 
749.       size_t j;
750.   
751. >     if (!TEST_ptr(sk_conf = NCONF_get_section(conf, test_section))
752.               || !TEST_ptr(ctx = SSL_TEST_CTX_new()))
753.           goto err;

crypto/conf/conf_lib.c:244:1: start of procedure NCONF_get_section()
  242.   }
  243.   
  244. > STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, const char *section)
  245.   {
  246.       if (conf == NULL) {

crypto/conf/conf_lib.c:246:9: Taking false branch
  244.   STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, const char *section)
  245.   {
  246.       if (conf == NULL) {
                 ^
  247.           CONFerr(CONF_F_NCONF_GET_SECTION, CONF_R_NO_CONF);
  248.           return NULL;

crypto/conf/conf_lib.c:251:9: Taking false branch
  249.       }
  250.   
  251.       if (section == NULL) {
                 ^
  252.           CONFerr(CONF_F_NCONF_GET_SECTION, CONF_R_NO_SECTION);
  253.           return NULL;

crypto/conf/conf_lib.c:256:5: 
  254.       }
  255.   
  256. >     return _CONF_get_section_values(conf, section);
  257.   }
  258.   

crypto/conf/conf_api.c:35:1: start of procedure _CONF_get_section_values()
    33.   
    34.   /* Up until OpenSSL 0.9.5a, this was CONF_get_section */
    35. > STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,
    36.                                                  const char *section)
    37.   {

crypto/conf/conf_api.c:40:5: 
    38.       CONF_VALUE *v;
    39.   
    40. >     v = _CONF_get_section(conf, section);
    41.       if (v != NULL)
    42.           return ((STACK_OF(CONF_VALUE) *)v->value);

crypto/conf/conf_api.c:22:1: start of procedure _CONF_get_section()
      20.   
      21.   /* Up until OpenSSL 0.9.5a, this was get_section */
      22. > CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section)
      23.   {
      24.       CONF_VALUE *v, vv;

crypto/conf/conf_api.c:26:10: Taking false branch
      24.       CONF_VALUE *v, vv;
      25.   
      26.       if ((conf == NULL) || (section == NULL))
                     ^
      27.           return (NULL);
      28.       vv.name = NULL;

crypto/conf/conf_api.c:26:28: Taking false branch
      24.       CONF_VALUE *v, vv;
      25.   
      26.       if ((conf == NULL) || (section == NULL))
                                       ^
      27.           return (NULL);
      28.       vv.name = NULL;

crypto/conf/conf_api.c:28:5: 
      26.       if ((conf == NULL) || (section == NULL))
      27.           return (NULL);
      28. >     vv.name = NULL;
      29.       vv.section = (char *)section;
      30.       v = lh_CONF_VALUE_retrieve(conf->data, &vv);

crypto/conf/conf_api.c:29:5: 
      27.           return (NULL);
      28.       vv.name = NULL;
      29. >     vv.section = (char *)section;
      30.       v = lh_CONF_VALUE_retrieve(conf->data, &vv);
      31.       return (v);

crypto/conf/conf_api.c:30:5: 
      28.       vv.name = NULL;
      29.       vv.section = (char *)section;
      30. >     v = lh_CONF_VALUE_retrieve(conf->data, &vv);
      31.       return (v);
      32.   }

include/openssl/conf.h:32:1: start of procedure lh_CONF_VALUE_retrieve()
        30.   
        31.   DEFINE_STACK_OF(CONF_VALUE)
        32. > DEFINE_LHASH_OF(CONF_VALUE);
        33.   
        34.   struct conf_st;

crypto/lhash/lhash.c:134:1: start of procedure OPENSSL_LH_retrieve()
          132.   }
          133.   
          134. > void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data)
          135.   {
          136.       unsigned long hash;

crypto/lhash/lhash.c:141:5: 
          139.       int scratch;
          140.   
          141. >     lh->error = 0;
          142.       rn = getrn(lh, data, &hash);
          143.   

crypto/lhash/lhash.c:142:5: Skipping getrn(): empty list of specs
          140.   
          141.       lh->error = 0;
          142.       rn = getrn(lh, data, &hash);
                     ^
          143.   
          144.       if (*rn == NULL) {

crypto/lhash/lhash.c:144:9: Taking false branch
          142.       rn = getrn(lh, data, &hash);
          143.   
          144.       if (*rn == NULL) {
                         ^
          145.           CRYPTO_atomic_add(&lh->num_retrieve_miss, 1, &scratch, lh->retrieve_stats_lock);
          146.           return NULL;

crypto/lhash/lhash.c:148:9: 
          146.           return NULL;
          147.       } else {
          148. >         ret = (*rn)->data;
          149.           CRYPTO_atomic_add(&lh->num_retrieve, 1, &scratch, lh->retrieve_stats_lock);
          150.       }

crypto/lhash/lhash.c:149:9: 
          147.       } else {
          148.           ret = (*rn)->data;
          149. >         CRYPTO_atomic_add(&lh->num_retrieve, 1, &scratch, lh->retrieve_stats_lock);
          150.       }
          151.       return ret;

crypto/threads_pthread.c:152:1: start of procedure CRYPTO_atomic_add()
            150.   }
            151.   
            152. > int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
            153.   {
            154.   # if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL)

crypto/threads_pthread.c:155:9: Taking false branch
            153.   {
            154.   # if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL)
            155.       if (__atomic_is_lock_free(sizeof(*val), val)) {
                           ^
            156.           *ret = __atomic_add_fetch(val, amount, __ATOMIC_ACQ_REL);
            157.           return 1;

crypto/threads_pthread.c:160:10: 
            158.       }
            159.   # endif
            160. >     if (!CRYPTO_THREAD_write_lock(lock))
            161.           return 0;
            162.   

crypto/threads_pthread.c:64:1: start of procedure CRYPTO_THREAD_write_lock()
              62.   }
              63.   
              64. > int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)
              65.   {
              66.   # ifdef USE_RWLOCK

crypto/threads_pthread.c:67:9: Taking true branch
              65.   {
              66.   # ifdef USE_RWLOCK
              67.       if (pthread_rwlock_wrlock(lock) != 0)
                            ^
              68.           return 0;
              69.   # else

crypto/threads_pthread.c:68:9: 
              66.   # ifdef USE_RWLOCK
              67.       if (pthread_rwlock_wrlock(lock) != 0)
              68. >         return 0;
              69.   # else
              70.       if (pthread_mutex_lock(lock) != 0)

crypto/threads_pthread.c:75:1: return from a call to CRYPTO_THREAD_write_lock
              73.   
              74.       return 1;
              75. > }
              76.   
              77.   int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)

crypto/threads_pthread.c:160:10: Taking true branch
            158.       }
            159.   # endif
            160.       if (!CRYPTO_THREAD_write_lock(lock))
                            ^
            161.           return 0;
            162.   

crypto/threads_pthread.c:161:9: 
            159.   # endif
            160.       if (!CRYPTO_THREAD_write_lock(lock))
            161. >         return 0;
            162.   
            163.       *val += amount;

crypto/threads_pthread.c:170:1: return from a call to CRYPTO_atomic_add
            168.   
            169.       return 1;
            170. > }
            171.   
            172.   # ifdef OPENSSL_SYS_UNIX

crypto/lhash/lhash.c:151:5: 
          149.           CRYPTO_atomic_add(&lh->num_retrieve, 1, &scratch, lh->retrieve_stats_lock);
          150.       }
          151. >     return ret;
          152.   }
          153.   

crypto/lhash/lhash.c:152:1: return from a call to OPENSSL_LH_retrieve
          150.       }
          151.       return ret;
          152. > }
          153.   
          154.   static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,

include/openssl/conf.h:32:1: return from a call to lh_CONF_VALUE_retrieve
        30.   
        31.   DEFINE_STACK_OF(CONF_VALUE)
        32. > DEFINE_LHASH_OF(CONF_VALUE);
        33.   
        34.   struct conf_st;

crypto/conf/conf_api.c:31:5: 
      29.       vv.section = (char *)section;
      30.       v = lh_CONF_VALUE_retrieve(conf->data, &vv);
      31. >     return (v);
      32.   }
      33.   

crypto/conf/conf_api.c:32:1: return from a call to _CONF_get_section
      30.       v = lh_CONF_VALUE_retrieve(conf->data, &vv);
      31.       return (v);
      32. > }
      33.   
      34.   /* Up until OpenSSL 0.9.5a, this was CONF_get_section */

crypto/conf/conf_api.c:41:9: Taking true branch
    39.   
    40.       v = _CONF_get_section(conf, section);
    41.       if (v != NULL)
                  ^
    42.           return ((STACK_OF(CONF_VALUE) *)v->value);
    43.       else

crypto/conf/conf_api.c:42:9: 
    40.       v = _CONF_get_section(conf, section);
    41.       if (v != NULL)
    42. >         return ((STACK_OF(CONF_VALUE) *)v->value);
    43.       else
    44.           return (NULL);

crypto/conf/conf_api.c:45:1: return from a call to _CONF_get_section_values
    43.       else
    44.           return (NULL);
    45. > }
    46.   
    47.   int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)

crypto/conf/conf_lib.c:257:1: return from a call to NCONF_get_section
  255.   
  256.       return _CONF_get_section_values(conf, section);
  257. > }
  258.   
  259.   char *NCONF_get_string(const CONF *conf, const char *group, const char *name)

test/testutil/tests.c:227:1: start of procedure test_ptr()
  225.   }
  226.   
  227. > int test_ptr(const char *file, int line, const char *s, const void *p)
  228.   {
  229.       if (p != NULL)

test/testutil/tests.c:229:9: Taking false branch
  227.   int test_ptr(const char *file, int line, const char *s, const void *p)
  228.   {
  229.       if (p != NULL)
                 ^
  230.           return 1;
  231.       test_fail_message(NULL, file, line, "ptr", s, "NULL", "!=", "%p", p);

test/testutil/tests.c:231:5: Skipping test_fail_message(): empty list of specs
  229.       if (p != NULL)
  230.           return 1;
  231.       test_fail_message(NULL, file, line, "ptr", s, "NULL", "!=", "%p", p);
             ^
  232.       return 0;
  233.   }

test/testutil/tests.c:232:5: 
  230.           return 1;
  231.       test_fail_message(NULL, file, line, "ptr", s, "NULL", "!=", "%p", p);
  232. >     return 0;
  233.   }
  234.   

test/testutil/tests.c:233:1: return from a call to test_ptr
  231.       test_fail_message(NULL, file, line, "ptr", s, "NULL", "!=", "%p", p);
  232.       return 0;
  233. > }
  234.   
  235.   int test_true(const char *file, int line, const char *s, int b)

test/ssl_test_ctx.c:751:10: Taking true branch
749.       size_t j;
750.   
751.       if (!TEST_ptr(sk_conf = NCONF_get_section(conf, test_section))
                ^
752.               || !TEST_ptr(ctx = SSL_TEST_CTX_new()))
753.           goto err;

test/ssl_test_ctx.c:802:2: 
800.       goto done;
801.   
802. >  err:
803.       SSL_TEST_CTX_free(ctx);
804.       ctx = NULL;

test/ssl_test_ctx.c:803:5: 
801.   
802.    err:
803. >     SSL_TEST_CTX_free(ctx);
804.       ctx = NULL;
805.    done:

SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section)
{
    STACK_OF(CONF_VALUE) *sk_conf = NULL;
    SSL_TEST_CTX *ctx = NULL;
    int i;
    size_t j;
    if (!TEST_ptr(sk_conf = NCONF_get_section(conf, test_section))
            || !TEST_ptr(ctx = SSL_TEST_CTX_new()))
        goto err;
    for (i = 0; i < sk_CONF_VALUE_num(sk_conf); i++) {
        int found = 0;
        const CONF_VALUE *option = sk_CONF_VALUE_value(sk_conf, i);
        if (strcmp(option->name, "client") == 0) {
            if (!parse_client_options(&ctx->extra.client, conf, option->value))
                goto err;
        } else if (strcmp(option->name, "server") == 0) {
            if (!parse_server_options(&ctx->extra.server, conf, option->value))
                goto err;
        } else if (strcmp(option->name, "server2") == 0) {
            if (!parse_server_options(&ctx->extra.server2, conf, option->value))
                goto err;
        } else if (strcmp(option->name, "resume-client") == 0) {
            if (!parse_client_options(&ctx->resume_extra.client, conf,
                                      option->value))
                goto err;
        } else if (strcmp(option->name, "resume-server") == 0) {
            if (!parse_server_options(&ctx->resume_extra.server, conf,
                                      option->value))
                goto err;
        } else if (strcmp(option->name, "resume-server2") == 0) {
            if (!parse_server_options(&ctx->resume_extra.server2, conf,
                                      option->value))
                goto err;
        } else {
            for (j = 0; j < OSSL_NELEM(ssl_test_ctx_options); j++) {
                if (strcmp(option->name, ssl_test_ctx_options[j].name) == 0) {
                    if (!ssl_test_ctx_options[j].parse(ctx, option->value)) {
                        TEST_info("Bad value %s for option %s",
                                   option->value, option->name);
                        goto err;
                    }
                    found = 1;
                    break;
                }
            }
            if (!found) {
                TEST_info("Unknown test option: %s", option->name);
                goto err;
            }
        }
    }
    goto done;
 err:
    SSL_TEST_CTX_free(ctx);
    ctx = NULL;
 done:
    return ctx;
}
['SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section)\n{\n    STACK_OF(CONF_VALUE) *sk_conf = NULL;\n    SSL_TEST_CTX *ctx = NULL;\n    int i;\n    size_t j;\n    if (!TEST_ptr(sk_conf = NCONF_get_section(conf, test_section))\n            || !TEST_ptr(ctx = SSL_TEST_CTX_new()))\n        goto err;\n    for (i = 0; i < sk_CONF_VALUE_num(sk_conf); i++) {\n        int found = 0;\n        const CONF_VALUE *option = sk_CONF_VALUE_value(sk_conf, i);\n        if (strcmp(option->name, "client") == 0) {\n            if (!parse_client_options(&ctx->extra.client, conf, option->value))\n                goto err;\n        } else if (strcmp(option->name, "server") == 0) {\n            if (!parse_server_options(&ctx->extra.server, conf, option->value))\n                goto err;\n        } else if (strcmp(option->name, "server2") == 0) {\n            if (!parse_server_options(&ctx->extra.server2, conf, option->value))\n                goto err;\n        } else if (strcmp(option->name, "resume-client") == 0) {\n            if (!parse_client_options(&ctx->resume_extra.client, conf,\n                                      option->value))\n                goto err;\n        } else if (strcmp(option->name, "resume-server") == 0) {\n            if (!parse_server_options(&ctx->resume_extra.server, conf,\n                                      option->value))\n                goto err;\n        } else if (strcmp(option->name, "resume-server2") == 0) {\n            if (!parse_server_options(&ctx->resume_extra.server2, conf,\n                                      option->value))\n                goto err;\n        } else {\n            for (j = 0; j < OSSL_NELEM(ssl_test_ctx_options); j++) {\n                if (strcmp(option->name, ssl_test_ctx_options[j].name) == 0) {\n                    if (!ssl_test_ctx_options[j].parse(ctx, option->value)) {\n                        TEST_info("Bad value %s for option %s",\n                                   option->value, option->name);\n                        goto err;\n                    }\n                    found = 1;\n                    break;\n                }\n            }\n            if (!found) {\n                TEST_info("Unknown test option: %s", option->name);\n                goto err;\n            }\n        }\n    }\n    goto done;\n err:\n    SSL_TEST_CTX_free(ctx);\n    ctx = NULL;\n done:\n    return ctx;\n}', 'STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, const char *section)\n{\n    if (conf == NULL) {\n        CONFerr(CONF_F_NCONF_GET_SECTION, CONF_R_NO_CONF);\n        return NULL;\n    }\n    if (section == NULL) {\n        CONFerr(CONF_F_NCONF_GET_SECTION, CONF_R_NO_SECTION);\n        return NULL;\n    }\n    return _CONF_get_section_values(conf, section);\n}', 'STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,\n                                               const char *section)\n{\n    CONF_VALUE *v;\n    v = _CONF_get_section(conf, section);\n    if (v != NULL)\n        return ((STACK_OF(CONF_VALUE) *)v->value);\n    else\n        return (NULL);\n}', 'CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section)\n{\n    CONF_VALUE *v, vv;\n    if ((conf == NULL) || (section == NULL))\n        return (NULL);\n    vv.name = NULL;\n    vv.section = (char *)section;\n    v = lh_CONF_VALUE_retrieve(conf->data, &vv);\n    return (v);\n}', 'void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data)\n{\n    unsigned long hash;\n    OPENSSL_LH_NODE **rn;\n    void *ret;\n    int scratch;\n    lh->error = 0;\n    rn = getrn(lh, data, &hash);\n    if (*rn == NULL) {\n        CRYPTO_atomic_add(&lh->num_retrieve_miss, 1, &scratch, lh->retrieve_stats_lock);\n        return NULL;\n    } else {\n        ret = (*rn)->data;\n        CRYPTO_atomic_add(&lh->num_retrieve, 1, &scratch, lh->retrieve_stats_lock);\n    }\n    return ret;\n}', 'int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)\n{\n# if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL)\n    if (__atomic_is_lock_free(sizeof(*val), val)) {\n        *ret = __atomic_add_fetch(val, amount, __ATOMIC_ACQ_REL);\n        return 1;\n    }\n# endif\n    if (!CRYPTO_THREAD_write_lock(lock))\n        return 0;\n    *val += amount;\n    *ret  = *val;\n    if (!CRYPTO_THREAD_unlock(lock))\n        return 0;\n    return 1;\n}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n    if (pthread_rwlock_wrlock(lock) != 0)\n        return 0;\n# else\n    if (pthread_mutex_lock(lock) != 0)\n        return 0;\n# endif\n    return 1;\n}', 'int test_ptr(const char *file, int line, const char *s, const void *p)\n{\n    if (p != NULL)\n        return 1;\n    test_fail_message(NULL, file, line, "ptr", s, "NULL", "!=", "%p", p);\n    return 0;\n}']