test/ct_test.c:298: error: NULL_DEREFERENCE
  pointer `&scts` last assigned on line 223 could be null and is dereferenced by call to `o2i_SCT_LIST()` at line 298, column 14.
Showing all 39 steps of the trace


test/ct_test.c:219:1: start of procedure execute_cert_test()
217.   }
218.   
219. > static int execute_cert_test(CT_TEST_FIXTURE *fixture)
220.   {
221.       int success = 0;

test/ct_test.c:221:5: 
219.   static int execute_cert_test(CT_TEST_FIXTURE *fixture)
220.   {
221. >     int success = 0;
222.       X509 *cert = NULL, *issuer = NULL;
223.       STACK_OF(SCT) *scts = NULL;

test/ct_test.c:222:5: 
220.   {
221.       int success = 0;
222. >     X509 *cert = NULL, *issuer = NULL;
223.       STACK_OF(SCT) *scts = NULL;
224.       SCT *sct = NULL;

test/ct_test.c:223:5: 
221.       int success = 0;
222.       X509 *cert = NULL, *issuer = NULL;
223. >     STACK_OF(SCT) *scts = NULL;
224.       SCT *sct = NULL;
225.       char expected_sct_text[CT_TEST_MAX_FILE_SIZE];

test/ct_test.c:224:5: 
222.       X509 *cert = NULL, *issuer = NULL;
223.       STACK_OF(SCT) *scts = NULL;
224. >     SCT *sct = NULL;
225.       char expected_sct_text[CT_TEST_MAX_FILE_SIZE];
226.       int sct_text_len = 0;

test/ct_test.c:226:5: 
224.       SCT *sct = NULL;
225.       char expected_sct_text[CT_TEST_MAX_FILE_SIZE];
226. >     int sct_text_len = 0;
227.       unsigned char *tls_sct_list = NULL;
228.       size_t tls_sct_list_len = 0;

test/ct_test.c:227:5: 
225.       char expected_sct_text[CT_TEST_MAX_FILE_SIZE];
226.       int sct_text_len = 0;
227. >     unsigned char *tls_sct_list = NULL;
228.       size_t tls_sct_list_len = 0;
229.       CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();

test/ct_test.c:228:5: 
226.       int sct_text_len = 0;
227.       unsigned char *tls_sct_list = NULL;
228. >     size_t tls_sct_list_len = 0;
229.       CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();
230.   

test/ct_test.c:229:5: Skipping CT_POLICY_EVAL_CTX_new(): empty list of specs
227.       unsigned char *tls_sct_list = NULL;
228.       size_t tls_sct_list_len = 0;
229.       CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();
           ^
230.   
231.       if (fixture->sct_text_file != NULL) {

test/ct_test.c:231:9: Taking false branch
229.       CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();
230.   
231.       if (fixture->sct_text_file != NULL) {
               ^
232.           sct_text_len = read_text_file(fixture->sct_dir, fixture->sct_text_file,
233.                                         expected_sct_text,

test/ct_test.c:241:5: 
239.       }
240.   
241. >     CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(
242.               ct_policy_ctx, fixture->ctlog_store);
243.   

crypto/ct/ct_policy.c:69:1: start of procedure CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE()
  67.   }
  68.   
  69. > void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,
  70.                                                  CTLOG_STORE *log_store)
  71.   {

crypto/ct/ct_policy.c:72:5: 
  70.                                                  CTLOG_STORE *log_store)
  71.   {
  72. >     ctx->log_store = log_store;
  73.   }
  74.   

crypto/ct/ct_policy.c:73:1: return from a call to CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE
  71.   {
  72.       ctx->log_store = log_store;
  73. > }
  74.   
  75.   void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms)

test/ct_test.c:244:5: 
242.               ct_policy_ctx, fixture->ctlog_store);
243.   
244. >     CT_POLICY_EVAL_CTX_set_time(ct_policy_ctx, fixture->epoch_time_in_ms);
245.   
246.       if (fixture->certificate_file != NULL) {

crypto/ct/ct_policy.c:75:1: start of procedure CT_POLICY_EVAL_CTX_set_time()
  73.   }
  74.   
  75. > void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms)
  76.   {
  77.       ctx->epoch_time_in_ms = time_in_ms;

crypto/ct/ct_policy.c:77:5: 
  75.   void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms)
  76.   {
  77. >     ctx->epoch_time_in_ms = time_in_ms;
  78.   }
  79.   

crypto/ct/ct_policy.c:78:1: return from a call to CT_POLICY_EVAL_CTX_set_time
  76.   {
  77.       ctx->epoch_time_in_ms = time_in_ms;
  78. > }
  79.   
  80.   X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx)

test/ct_test.c:246:9: Taking false branch
244.       CT_POLICY_EVAL_CTX_set_time(ct_policy_ctx, fixture->epoch_time_in_ms);
245.   
246.       if (fixture->certificate_file != NULL) {
               ^
247.           int sct_extension_index;
248.           int i;

test/ct_test.c:295:9: Taking true branch
293.       }
294.   
295.       if (fixture->tls_sct_list != NULL) {
               ^
296.           const unsigned char *p = fixture->tls_sct_list;
297.   

test/ct_test.c:296:9: 
294.   
295.       if (fixture->tls_sct_list != NULL) {
296. >         const unsigned char *p = fixture->tls_sct_list;
297.   
298.           if (!TEST_ptr(o2i_SCT_LIST(&scts, &p, fixture->tls_sct_list_len)))

test/ct_test.c:298:14: 
296.           const unsigned char *p = fixture->tls_sct_list;
297.   
298. >         if (!TEST_ptr(o2i_SCT_LIST(&scts, &p, fixture->tls_sct_list_len)))
299.               goto end;
300.   

crypto/ct/ct_oct.c:257:1: start of procedure o2i_SCT_LIST()
  255.   }
  256.   
  257. > STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp,
  258.                               size_t len)
  259.   {

crypto/ct/ct_oct.c:260:5: 
  258.                               size_t len)
  259.   {
  260. >     STACK_OF(SCT) *sk = NULL;
  261.       size_t list_len, sct_len;
  262.   

crypto/ct/ct_oct.c:263:9: Taking false branch
  261.       size_t list_len, sct_len;
  262.   
  263.       if (len < 2 || len > MAX_SCT_LIST_SIZE) {
                 ^
  264.           CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);
  265.           return NULL;

crypto/ct/ct_oct.c:263:20: Taking false branch
  261.       size_t list_len, sct_len;
  262.   
  263.       if (len < 2 || len > MAX_SCT_LIST_SIZE) {
                            ^
  264.           CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);
  265.           return NULL;

crypto/ct/ct_oct.c:268:5: 
  266.       }
  267.   
  268. >     n2s(*pp, list_len);
  269.       if (list_len != len - 2) {
  270.           CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);

crypto/ct/ct_oct.c:269:9: Taking false branch
  267.   
  268.       n2s(*pp, list_len);
  269.       if (list_len != len - 2) {
                 ^
  270.           CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);
  271.           return NULL;

crypto/ct/ct_oct.c:274:9: Taking false branch
  272.       }
  273.   
  274.       if (a == NULL || *a == NULL) {
                 ^
  275.           sk = sk_SCT_new_null();
  276.           if (sk == NULL)

crypto/ct/ct_oct.c:274:22: Taking false branch
  272.       }
  273.   
  274.       if (a == NULL || *a == NULL) {
                              ^
  275.           sk = sk_SCT_new_null();
  276.           if (sk == NULL)

crypto/ct/ct_oct.c:282:9: 
  280.   
  281.           /* Use the given stack, but empty it first. */
  282. >         sk = *a;
  283.           while ((sct = sk_SCT_pop(sk)) != NULL)
  284.               SCT_free(sct);

crypto/ct/ct_oct.c:283:16: 
  281.           /* Use the given stack, but empty it first. */
  282.           sk = *a;
  283. >         while ((sct = sk_SCT_pop(sk)) != NULL)
  284.               SCT_free(sct);
  285.       }

include/openssl/ct.h:58:1: start of procedure sk_SCT_pop()
    56.   } sct_validation_status_t;
    57.   
    58. > DEFINE_STACK_OF(SCT)
    59.   DEFINE_STACK_OF(CTLOG)
    60.   

crypto/stack/stack.c:344:1: start of procedure OPENSSL_sk_pop()
      342.   }
      343.   
      344. > void *OPENSSL_sk_pop(OPENSSL_STACK *st)
      345.   {
      346.       if (st == NULL || st->num == 0)

crypto/stack/stack.c:346:9: Taking false branch
      344.   void *OPENSSL_sk_pop(OPENSSL_STACK *st)
      345.   {
      346.       if (st == NULL || st->num == 0)
                     ^
      347.           return NULL;
      348.       return internal_delete(st, st->num - 1);

crypto/stack/stack.c:346:23: Taking false branch
      344.   void *OPENSSL_sk_pop(OPENSSL_STACK *st)
      345.   {
      346.       if (st == NULL || st->num == 0)
                                   ^
      347.           return NULL;
      348.       return internal_delete(st, st->num - 1);

crypto/stack/stack.c:348:5: 
      346.       if (st == NULL || st->num == 0)
      347.           return NULL;
      348. >     return internal_delete(st, st->num - 1);
      349.   }
      350.   

crypto/stack/stack.c:256:1: start of procedure internal_delete()
        254.   }
        255.   
        256. > static ossl_inline void *internal_delete(OPENSSL_STACK *st, int loc)
        257.   {
        258.       const void *ret = st->data[loc];

crypto/stack/stack.c:258:5: 
        256.   static ossl_inline void *internal_delete(OPENSSL_STACK *st, int loc)
        257.   {
        258. >     const void *ret = st->data[loc];
        259.   
        260.       if (loc != st->num - 1)

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 (!TEST_int_ge(sct_text_len, 0))
            goto end;
        expected_sct_text[sct_text_len] = '\0';
    }
    CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(
            ct_policy_ctx, fixture->ctlog_store);
    CT_POLICY_EVAL_CTX_set_time(ct_policy_ctx, fixture->epoch_time_in_ms);
    if (fixture->certificate_file != NULL) {
        int sct_extension_index;
        int i;
        X509_EXTENSION *sct_extension = NULL;
        if (!TEST_ptr(cert = load_pem_cert(fixture->certs_dir,
                                           fixture->certificate_file)))
            goto end;
        CT_POLICY_EVAL_CTX_set1_cert(ct_policy_ctx, cert);
        if (fixture->issuer_file != NULL) {
            if (!TEST_ptr(issuer = load_pem_cert(fixture->certs_dir,
                                                 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 (!TEST_ptr(sct_extension))
                goto end;
            if (fixture->sct_text_file
                && !compare_extension_printout(sct_extension,
                                               expected_sct_text))
                    goto end;
            scts = X509V3_EXT_d2i(sct_extension);
            for (i = 0; i < sk_SCT_num(scts); ++i) {
                SCT *sct_i = sk_SCT_value(scts, i);
                if (!TEST_int_eq(SCT_get_source(sct_i),
                                 SCT_SOURCE_X509V3_EXTENSION)) {
                    goto end;
                }
            }
            if (fixture->test_validity) {
                if (!assert_validity(fixture, scts, ct_policy_ctx))
                    goto end;
            }
        } else if (!TEST_ptr_null(sct_extension)) {
            goto end;
        }
    }
    if (fixture->tls_sct_list != NULL) {
        const unsigned char *p = fixture->tls_sct_list;
        if (!TEST_ptr(o2i_SCT_LIST(&scts, &p, fixture->tls_sct_list_len)))
            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 (!TEST_mem_eq(fixture->tls_sct_list, fixture->tls_sct_list_len,
                         tls_sct_list, tls_sct_list_len))
            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 (!TEST_int_ge(sct_text_len, 0))\n            goto end;\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    CT_POLICY_EVAL_CTX_set_time(ct_policy_ctx, fixture->epoch_time_in_ms);\n    if (fixture->certificate_file != NULL) {\n        int sct_extension_index;\n        int i;\n        X509_EXTENSION *sct_extension = NULL;\n        if (!TEST_ptr(cert = load_pem_cert(fixture->certs_dir,\n                                           fixture->certificate_file)))\n            goto end;\n        CT_POLICY_EVAL_CTX_set1_cert(ct_policy_ctx, cert);\n        if (fixture->issuer_file != NULL) {\n            if (!TEST_ptr(issuer = load_pem_cert(fixture->certs_dir,\n                                                 fixture->issuer_file)))\n                goto end;\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 (!TEST_ptr(sct_extension))\n                goto end;\n            if (fixture->sct_text_file\n                && !compare_extension_printout(sct_extension,\n                                               expected_sct_text))\n                    goto end;\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 (!TEST_int_eq(SCT_get_source(sct_i),\n                                 SCT_SOURCE_X509V3_EXTENSION)) {\n                    goto end;\n                }\n            }\n            if (fixture->test_validity) {\n                if (!assert_validity(fixture, scts, ct_policy_ctx))\n                    goto end;\n            }\n        } else if (!TEST_ptr_null(sct_extension)) {\n            goto end;\n        }\n    }\n    if (fixture->tls_sct_list != NULL) {\n        const unsigned char *p = fixture->tls_sct_list;\n        if (!TEST_ptr(o2i_SCT_LIST(&scts, &p, fixture->tls_sct_list_len)))\n            goto end;\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 (!TEST_mem_eq(fixture->tls_sct_list, fixture->tls_sct_list_len,\n                         tls_sct_list, tls_sct_list_len))\n            goto end;\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}", '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}', 'void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms)\n{\n    ctx->epoch_time_in_ms = time_in_ms;\n}', 'STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp,\n                            size_t len)\n{\n    STACK_OF(SCT) *sk = NULL;\n    size_t list_len, sct_len;\n    if (len < 2 || len > MAX_SCT_LIST_SIZE) {\n        CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);\n        return NULL;\n    }\n    n2s(*pp, list_len);\n    if (list_len != len - 2) {\n        CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);\n        return NULL;\n    }\n    if (a == NULL || *a == NULL) {\n        sk = sk_SCT_new_null();\n        if (sk == NULL)\n            return NULL;\n    } else {\n        SCT *sct;\n        sk = *a;\n        while ((sct = sk_SCT_pop(sk)) != NULL)\n            SCT_free(sct);\n    }\n    while (list_len > 0) {\n        SCT *sct;\n        if (list_len < 2) {\n            CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);\n            goto err;\n        }\n        n2s(*pp, sct_len);\n        list_len -= 2;\n        if (sct_len == 0 || sct_len > list_len) {\n            CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);\n            goto err;\n        }\n        list_len -= sct_len;\n        if ((sct = o2i_SCT(NULL, pp, sct_len)) == NULL)\n            goto err;\n        if (!sk_SCT_push(sk, sct)) {\n            SCT_free(sct);\n            goto err;\n        }\n    }\n    if (a != NULL && *a == NULL)\n        *a = sk;\n    return sk;\n err:\n    if (a == NULL || *a == NULL)\n        SCT_LIST_free(sk);\n    return NULL;\n}', 'void *OPENSSL_sk_pop(OPENSSL_STACK *st)\n{\n    if (st == NULL || st->num == 0)\n        return NULL;\n    return internal_delete(st, st->num - 1);\n}', 'static ossl_inline void *internal_delete(OPENSSL_STACK *st, int loc)\n{\n    const void *ret = st->data[loc];\n    if (loc != st->num - 1)\n         memmove(&st->data[loc], &st->data[loc + 1],\n                 sizeof(st->data[0]) * (st->num - loc - 1));\n    st->num--;\n    return (void *)ret;\n}']