test/ct_test.c:300: error: NULL_DEREFERENCE
  pointer `ct_policy_ctx` last assigned on line 284 could be null and is dereferenced by call to `CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE()` at line 300, column 5.
Showing all 34 steps of the trace


test/ct_test.c:274:1: start of procedure execute_cert_test()
272.   }
273.   
274. > static int execute_cert_test(CT_TEST_FIXTURE fixture)
275.   {
276.       int success = 0;

test/ct_test.c:276:5: 
274.   static int execute_cert_test(CT_TEST_FIXTURE fixture)
275.   {
276. >     int success = 0;
277.       X509 *cert = NULL, *issuer = NULL;
278.       STACK_OF(SCT) *scts = NULL;

test/ct_test.c:277:5: 
275.   {
276.       int success = 0;
277. >     X509 *cert = NULL, *issuer = NULL;
278.       STACK_OF(SCT) *scts = NULL;
279.       SCT *sct = NULL;

test/ct_test.c:278:5: 
276.       int success = 0;
277.       X509 *cert = NULL, *issuer = NULL;
278. >     STACK_OF(SCT) *scts = NULL;
279.       SCT *sct = NULL;
280.       char expected_sct_text[CT_TEST_MAX_FILE_SIZE];

test/ct_test.c:279:5: 
277.       X509 *cert = NULL, *issuer = NULL;
278.       STACK_OF(SCT) *scts = NULL;
279. >     SCT *sct = NULL;
280.       char expected_sct_text[CT_TEST_MAX_FILE_SIZE];
281.       int sct_text_len = 0;

test/ct_test.c:281:5: 
279.       SCT *sct = NULL;
280.       char expected_sct_text[CT_TEST_MAX_FILE_SIZE];
281. >     int sct_text_len = 0;
282.       unsigned char *tls_sct_list = NULL;
283.       size_t tls_sct_list_len = 0;

test/ct_test.c:282:5: 
280.       char expected_sct_text[CT_TEST_MAX_FILE_SIZE];
281.       int sct_text_len = 0;
282. >     unsigned char *tls_sct_list = NULL;
283.       size_t tls_sct_list_len = 0;
284.       CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();

test/ct_test.c:283:5: 
281.       int sct_text_len = 0;
282.       unsigned char *tls_sct_list = NULL;
283. >     size_t tls_sct_list_len = 0;
284.       CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();
285.   

test/ct_test.c:284:5: 
282.       unsigned char *tls_sct_list = NULL;
283.       size_t tls_sct_list_len = 0;
284. >     CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();
285.   
286.       if (fixture.sct_text_file != NULL) {

crypto/ct/ct_policy.c:19:1: start of procedure CT_POLICY_EVAL_CTX_new()
  17.   #include "ct_locl.h"
  18.   
  19. > CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void)
  20.   {
  21.       CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX));

crypto/ct/ct_policy.c:21:5: 
  19.   CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void)
  20.   {
  21. >     CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX));
  22.   
  23.       if (ctx == NULL) {

crypto/mem.c:98:1: start of procedure CRYPTO_zalloc()
    96.   }
    97.   
    98. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:100:5: 
    98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100. >     void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)

crypto/mem.c:71:1: start of procedure CRYPTO_malloc()
      69.   }
      70.   
      71. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      72.   {
      73.       void *ret = NULL;

crypto/mem.c:73:5: 
      71.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      72.   {
      73. >     void *ret = NULL;
      74.   
      75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:75:9: Taking false branch
      73.       void *ret = NULL;
      74.   
      75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                    ^
      76.           return malloc_impl(num, file, line);
      77.   

crypto/mem.c:78:9: Taking false branch
      76.           return malloc_impl(num, file, line);
      77.   
      78.       if (num <= 0)
                    ^
      79.           return NULL;
      80.   

crypto/mem.c:81:5: 
      79.           return NULL;
      80.   
      81. >     allow_customize = 0;
      82.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      83.       if (call_malloc_debug) {

crypto/mem.c:91:5: 
      89.       }
      90.   #else
      91. >     osslargused(file); osslargused(line);
      92.       ret = malloc(num);
      93.   #endif

crypto/mem.c:91:24: 
      89.       }
      90.   #else
      91. >     osslargused(file); osslargused(line);
      92.       ret = malloc(num);
      93.   #endif

crypto/mem.c:92:5: 
      90.   #else
      91.       osslargused(file); osslargused(line);
      92. >     ret = malloc(num);
      93.   #endif
      94.   

crypto/mem.c:95:5: 
      93.   #endif
      94.   
      95. >     return ret;
      96.   }
      97.   

crypto/mem.c:96:1: return from a call to CRYPTO_malloc
      94.   
      95.       return ret;
      96. > }
      97.   
      98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:102:9: Taking false branch
    100.       void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)
                   ^
    103.           memset(ret, 0, num);
    104.       return ret;

crypto/mem.c:104:5: 
    102.       if (ret != NULL)
    103.           memset(ret, 0, num);
    104. >     return ret;
    105.   }
    106.   

crypto/mem.c:105:1: return from a call to CRYPTO_zalloc
    103.           memset(ret, 0, num);
    104.       return ret;
    105. > }
    106.   
    107.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/ct/ct_policy.c:23:9: Taking true branch
  21.       CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX));
  22.   
  23.       if (ctx == NULL) {
                ^
  24.           CTerr(CT_F_CT_POLICY_EVAL_CTX_NEW, ERR_R_MALLOC_FAILURE);
  25.           return NULL;

crypto/ct/ct_policy.c:24:9: Skipping ERR_put_error(): empty list of specs
  22.   
  23.       if (ctx == NULL) {
  24.           CTerr(CT_F_CT_POLICY_EVAL_CTX_NEW, ERR_R_MALLOC_FAILURE);
                ^
  25.           return NULL;
  26.       }

crypto/ct/ct_policy.c:25:9: 
  23.       if (ctx == NULL) {
  24.           CTerr(CT_F_CT_POLICY_EVAL_CTX_NEW, ERR_R_MALLOC_FAILURE);
  25. >         return NULL;
  26.       }
  27.   

crypto/ct/ct_policy.c:29:1: return from a call to CT_POLICY_EVAL_CTX_new
  27.   
  28.       return ctx;
  29. > }
  30.   
  31.   void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx)

test/ct_test.c:286:9: Taking false branch
284.       CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();
285.   
286.       if (fixture.sct_text_file != NULL) {
               ^
287.           sct_text_len = read_text_file(fixture.sct_dir, fixture.sct_text_file,
288.                                         expected_sct_text,

test/ct_test.c:300:5: 
298.       }
299.   
300. >     CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(
301.               ct_policy_ctx, fixture.ctlog_store);
302.   

crypto/ct/ct_policy.c:56:1: start of procedure CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE()
  54.   }
  55.   
  56. > void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,
  57.                                                  CTLOG_STORE *log_store)
  58.   {

crypto/ct/ct_policy.c:59:5: 
  57.                                                  CTLOG_STORE *log_store)
  58.   {
  59. >     ctx->log_store = log_store;
  60.   }
  61.   

static int execute_cert_test(CT_TEST_FIXTURE fixture)
{
    int success = 0;
    X509 *cert = NULL, *issuer = NULL;
    STACK_OF(SCT) *scts = NULL;
    SCT *sct = NULL;
    char expected_sct_text[CT_TEST_MAX_FILE_SIZE];
    int sct_text_len = 0;
    unsigned char *tls_sct_list = NULL;
    size_t tls_sct_list_len = 0;
    CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();
    if (fixture.sct_text_file != NULL) {
        sct_text_len = read_text_file(fixture.sct_dir, fixture.sct_text_file,
                                      expected_sct_text,
                                      CT_TEST_MAX_FILE_SIZE - 1);
        if (sct_text_len < 0) {
            fprintf(stderr, "Test data file not found: %s\n",
                fixture.sct_text_file);
            goto end;
        }
        expected_sct_text[sct_text_len] = '\0';
    }
    CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(
            ct_policy_ctx, fixture.ctlog_store);
    if (fixture.certificate_file != NULL) {
        int sct_extension_index;
        X509_EXTENSION *sct_extension = NULL;
        cert = load_pem_cert(fixture.certs_dir, fixture.certificate_file);
        if (cert == NULL) {
            fprintf(stderr, "Unable to load certificate: %s\n",
                fixture.certificate_file);
            goto end;
        }
        CT_POLICY_EVAL_CTX_set1_cert(ct_policy_ctx, cert);
        if (fixture.issuer_file != NULL) {
            issuer = load_pem_cert(fixture.certs_dir, fixture.issuer_file);
            if (issuer == NULL) {
                fprintf(stderr, "Unable to load issuer certificate: %s\n",
                        fixture.issuer_file);
                goto end;
            }
            CT_POLICY_EVAL_CTX_set1_issuer(ct_policy_ctx, issuer);
        }
        sct_extension_index =
                X509_get_ext_by_NID(cert, NID_ct_precert_scts, -1);
        sct_extension = X509_get_ext(cert, sct_extension_index);
        if (fixture.expected_sct_count > 0) {
            if (sct_extension == NULL) {
                fprintf(stderr, "SCT extension not found in: %s\n",
                    fixture.certificate_file);
                goto end;
            }
            if (fixture.sct_text_file
                && compare_extension_printout(sct_extension,
                                              expected_sct_text)) {
                    goto end;
            }
            if (fixture.test_validity) {
                int i;
                scts = X509V3_EXT_d2i(sct_extension);
                for (i = 0; i < sk_SCT_num(scts); ++i) {
                    SCT *sct_i = sk_SCT_value(scts, i);
                    if (!SCT_set_source(sct_i, SCT_SOURCE_X509V3_EXTENSION)) {
                        fprintf(stderr,
                                "Error setting SCT source to X509v3 extension\n");
                        goto end;
                    }
                }
                if (!assert_validity(fixture, scts, ct_policy_ctx))
                    goto end;
            }
        } else if (sct_extension != NULL) {
            fprintf(stderr,
                    "Expected no SCTs, but found SCT extension in: %s\n",
                    fixture.certificate_file);
            goto end;
        }
    }
    if (fixture.tls_sct_list != NULL) {
        const unsigned char *p = fixture.tls_sct_list;
        if (o2i_SCT_LIST(&scts, &p, fixture.tls_sct_list_len) == NULL) {
            fprintf(stderr, "Failed to decode SCTs from TLS format\n");
            goto end;
        }
        if (fixture.test_validity && cert != NULL) {
            if (!assert_validity(fixture, scts, ct_policy_ctx))
                goto end;
        }
        if (fixture.sct_text_file
            && compare_sct_list_printout(scts, expected_sct_text)) {
                goto end;
        }
        tls_sct_list_len = i2o_SCT_LIST(scts, &tls_sct_list);
        if (tls_sct_list_len != fixture.tls_sct_list_len ||
            memcmp(fixture.tls_sct_list, tls_sct_list, tls_sct_list_len) != 0) {
            fprintf(stderr,
                    "Failed to encode SCTs into TLS format correctly\n");
            goto end;
        }
    }
    success = 1;
end:
    X509_free(cert);
    X509_free(issuer);
    SCT_LIST_free(scts);
    SCT_free(sct);
    CT_POLICY_EVAL_CTX_free(ct_policy_ctx);
    OPENSSL_free(tls_sct_list);
    return success;
}
['static int execute_cert_test(CT_TEST_FIXTURE fixture)\n{\n    int success = 0;\n    X509 *cert = NULL, *issuer = NULL;\n    STACK_OF(SCT) *scts = NULL;\n    SCT *sct = NULL;\n    char expected_sct_text[CT_TEST_MAX_FILE_SIZE];\n    int sct_text_len = 0;\n    unsigned char *tls_sct_list = NULL;\n    size_t tls_sct_list_len = 0;\n    CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();\n    if (fixture.sct_text_file != NULL) {\n        sct_text_len = read_text_file(fixture.sct_dir, fixture.sct_text_file,\n                                      expected_sct_text,\n                                      CT_TEST_MAX_FILE_SIZE - 1);\n        if (sct_text_len < 0) {\n            fprintf(stderr, "Test data file not found: %s\\n",\n                fixture.sct_text_file);\n            goto end;\n        }\n        expected_sct_text[sct_text_len] = \'\\0\';\n    }\n    CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(\n            ct_policy_ctx, fixture.ctlog_store);\n    if (fixture.certificate_file != NULL) {\n        int sct_extension_index;\n        X509_EXTENSION *sct_extension = NULL;\n        cert = load_pem_cert(fixture.certs_dir, fixture.certificate_file);\n        if (cert == NULL) {\n            fprintf(stderr, "Unable to load certificate: %s\\n",\n                fixture.certificate_file);\n            goto end;\n        }\n        CT_POLICY_EVAL_CTX_set1_cert(ct_policy_ctx, cert);\n        if (fixture.issuer_file != NULL) {\n            issuer = load_pem_cert(fixture.certs_dir, fixture.issuer_file);\n            if (issuer == NULL) {\n                fprintf(stderr, "Unable to load issuer certificate: %s\\n",\n                        fixture.issuer_file);\n                goto end;\n            }\n            CT_POLICY_EVAL_CTX_set1_issuer(ct_policy_ctx, issuer);\n        }\n        sct_extension_index =\n                X509_get_ext_by_NID(cert, NID_ct_precert_scts, -1);\n        sct_extension = X509_get_ext(cert, sct_extension_index);\n        if (fixture.expected_sct_count > 0) {\n            if (sct_extension == NULL) {\n                fprintf(stderr, "SCT extension not found in: %s\\n",\n                    fixture.certificate_file);\n                goto end;\n            }\n            if (fixture.sct_text_file\n                && compare_extension_printout(sct_extension,\n                                              expected_sct_text)) {\n                    goto end;\n            }\n            if (fixture.test_validity) {\n                int i;\n                scts = X509V3_EXT_d2i(sct_extension);\n                for (i = 0; i < sk_SCT_num(scts); ++i) {\n                    SCT *sct_i = sk_SCT_value(scts, i);\n                    if (!SCT_set_source(sct_i, SCT_SOURCE_X509V3_EXTENSION)) {\n                        fprintf(stderr,\n                                "Error setting SCT source to X509v3 extension\\n");\n                        goto end;\n                    }\n                }\n                if (!assert_validity(fixture, scts, ct_policy_ctx))\n                    goto end;\n            }\n        } else if (sct_extension != NULL) {\n            fprintf(stderr,\n                    "Expected no SCTs, but found SCT extension in: %s\\n",\n                    fixture.certificate_file);\n            goto end;\n        }\n    }\n    if (fixture.tls_sct_list != NULL) {\n        const unsigned char *p = fixture.tls_sct_list;\n        if (o2i_SCT_LIST(&scts, &p, fixture.tls_sct_list_len) == NULL) {\n            fprintf(stderr, "Failed to decode SCTs from TLS format\\n");\n            goto end;\n        }\n        if (fixture.test_validity && cert != NULL) {\n            if (!assert_validity(fixture, scts, ct_policy_ctx))\n                goto end;\n        }\n        if (fixture.sct_text_file\n            && compare_sct_list_printout(scts, expected_sct_text)) {\n                goto end;\n        }\n        tls_sct_list_len = i2o_SCT_LIST(scts, &tls_sct_list);\n        if (tls_sct_list_len != fixture.tls_sct_list_len ||\n            memcmp(fixture.tls_sct_list, tls_sct_list, tls_sct_list_len) != 0) {\n            fprintf(stderr,\n                    "Failed to encode SCTs into TLS format correctly\\n");\n            goto end;\n        }\n    }\n    success = 1;\nend:\n    X509_free(cert);\n    X509_free(issuer);\n    SCT_LIST_free(scts);\n    SCT_free(sct);\n    CT_POLICY_EVAL_CTX_free(ct_policy_ctx);\n    OPENSSL_free(tls_sct_list);\n    return success;\n}', 'CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void)\n{\n    CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX));\n    if (ctx == NULL) {\n        CTerr(CT_F_CT_POLICY_EVAL_CTX_NEW, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    return ctx;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\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    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}', 'void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,\n                                               CTLOG_STORE *log_store)\n{\n    ctx->log_store = log_store;\n}']