apps/x509.c:993: error: NULL_DEREFERENCE
  pointer `upkey` last assigned on line 992 could be null and is dereferenced by call to `EVP_PKEY_copy_parameters()` at line 993, column 5.
Showing all 22 steps of the trace


apps/x509.c:980:1: start of procedure x509_certify()
978.   }
979.   
980. > static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
981.                           X509 *x, X509 *xca, EVP_PKEY *pkey,
982.                           STACK_OF(OPENSSL_STRING) *sigopts,

apps/x509.c:987:5: 
985.                           ASN1_INTEGER *sno, int reqfile)
986.   {
987. >     int ret = 0;
988.       ASN1_INTEGER *bs = NULL;
989.       X509_STORE_CTX xsc;

apps/x509.c:988:5: 
986.   {
987.       int ret = 0;
988. >     ASN1_INTEGER *bs = NULL;
989.       X509_STORE_CTX xsc;
990.       EVP_PKEY *upkey;

apps/x509.c:992:5: 
990.       EVP_PKEY *upkey;
991.   
992. >     upkey = X509_get0_pubkey(xca);
993.       EVP_PKEY_copy_parameters(upkey, pkey);
994.   

crypto/x509/x509_cmp.c:308:1: start of procedure X509_get0_pubkey()
  306.   }
  307.   
  308. > EVP_PKEY *X509_get0_pubkey(X509 *x)
  309.   {
  310.       if (x == NULL)

crypto/x509/x509_cmp.c:310:9: Taking false branch
  308.   EVP_PKEY *X509_get0_pubkey(X509 *x)
  309.   {
  310.       if (x == NULL)
                 ^
  311.           return NULL;
  312.       return X509_PUBKEY_get0(x->cert_info.key);

crypto/x509/x509_cmp.c:312:5: 
  310.       if (x == NULL)
  311.           return NULL;
  312. >     return X509_PUBKEY_get0(x->cert_info.key);
  313.   }
  314.   

crypto/asn1/x_pubkey.c:124:1: start of procedure X509_PUBKEY_get0()
    122.   }
    123.   
    124. > EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)
    125.   {
    126.       EVP_PKEY *ret = NULL;

crypto/asn1/x_pubkey.c:126:5: 
    124.   EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)
    125.   {
    126. >     EVP_PKEY *ret = NULL;
    127.   
    128.       if (key == NULL)

crypto/asn1/x_pubkey.c:128:9: Taking false branch
    126.       EVP_PKEY *ret = NULL;
    127.   
    128.       if (key == NULL)
                   ^
    129.           goto error;
    130.   

crypto/asn1/x_pubkey.c:131:9: Taking false branch
    129.           goto error;
    130.   
    131.       if (key->pkey != NULL)
                   ^
    132.           return key->pkey;
    133.   

crypto/asn1/x_pubkey.c:134:9: Taking true branch
    132.           return key->pkey;
    133.   
    134.       if (key->public_key == NULL)
                   ^
    135.           goto error;
    136.   

crypto/asn1/x_pubkey.c:170:2: 
    168.       return ret;
    169.   
    170. >  error:
    171.       EVP_PKEY_free(ret);
    172.       return (NULL);

crypto/asn1/x_pubkey.c:171:5: 
    169.   
    170.    error:
    171. >     EVP_PKEY_free(ret);
    172.       return (NULL);
    173.   }

crypto/evp/p_lib.c:420:1: start of procedure EVP_PKEY_free()
      418.   }
      419.   
      420. > void EVP_PKEY_free(EVP_PKEY *x)
      421.   {
      422.       int i;

crypto/evp/p_lib.c:424:9: Taking true branch
      422.       int i;
      423.   
      424.       if (x == NULL)
                     ^
      425.           return;
      426.   

crypto/evp/p_lib.c:425:9: 
      423.   
      424.       if (x == NULL)
      425. >         return;
      426.   
      427.       i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY);

crypto/evp/p_lib.c:442:1: return from a call to EVP_PKEY_free
      440.       sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
      441.       OPENSSL_free(x);
      442. > }
      443.   
      444.   static void EVP_PKEY_free_it(EVP_PKEY *x)

crypto/asn1/x_pubkey.c:172:5: 
    170.    error:
    171.       EVP_PKEY_free(ret);
    172. >     return (NULL);
    173.   }
    174.   

crypto/asn1/x_pubkey.c:173:1: return from a call to X509_PUBKEY_get0
    171.       EVP_PKEY_free(ret);
    172.       return (NULL);
    173. > }
    174.   
    175.   EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)

crypto/x509/x509_cmp.c:313:1: return from a call to X509_get0_pubkey
  311.           return NULL;
  312.       return X509_PUBKEY_get0(x->cert_info.key);
  313. > }
  314.   
  315.   EVP_PKEY *X509_get_pubkey(X509 *x)

apps/x509.c:993:5: 
991.   
992.       upkey = X509_get0_pubkey(xca);
993. >     EVP_PKEY_copy_parameters(upkey, pkey);
994.   
995.       if (!X509_STORE_CTX_init(&xsc, ctx, x, NULL)) {

static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
                        X509 *x, X509 *xca, EVP_PKEY *pkey,
                        STACK_OF(OPENSSL_STRING) *sigopts,
                        char *serialfile, int create,
                        int days, int clrext, CONF *conf, char *section,
                        ASN1_INTEGER *sno, int reqfile)
{
    int ret = 0;
    ASN1_INTEGER *bs = NULL;
    X509_STORE_CTX xsc;
    EVP_PKEY *upkey;
    upkey = X509_get0_pubkey(xca);
    EVP_PKEY_copy_parameters(upkey, pkey);
    if (!X509_STORE_CTX_init(&xsc, ctx, x, NULL)) {
        BIO_printf(bio_err, "Error initialising X509 store\n");
        goto end;
    }
    if (sno)
        bs = sno;
    else if ((bs = x509_load_serial(CAfile, serialfile, create)) == NULL)
        goto end;
    X509_STORE_CTX_set_cert(&xsc, x);
    X509_STORE_CTX_set_flags(&xsc, X509_V_FLAG_CHECK_SS_SIGNATURE);
    if (!reqfile && X509_verify_cert(&xsc) <= 0)
        goto end;
    if (!X509_check_private_key(xca, pkey)) {
        BIO_printf(bio_err,
                   "CA certificate and CA private key do not match\n");
        goto end;
    }
    if (!X509_set_issuer_name(x, X509_get_subject_name(xca)))
        goto end;
    if (!X509_set_serialNumber(x, bs))
        goto end;
    if (X509_gmtime_adj(X509_get_notBefore(x), 0L) == NULL)
        goto end;
    if (X509_time_adj_ex(X509_get_notAfter(x), days, 0, NULL) == NULL)
        goto end;
    if (clrext) {
        while (X509_get_ext_count(x) > 0)
            X509_delete_ext(x, 0);
    }
    if (conf) {
        X509V3_CTX ctx2;
#ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL
        X509_set_version(x, force_version);
#else
        X509_set_version(x, 2);
#endif
        X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);
        X509V3_set_nconf(&ctx2, conf);
        if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x))
            goto end;
    }
    if (!do_X509_sign(x, pkey, digest, sigopts))
        goto end;
    ret = 1;
 end:
    X509_STORE_CTX_cleanup(&xsc);
    if (!ret)
        ERR_print_errors(bio_err);
    if (!sno)
        ASN1_INTEGER_free(bs);
    return ret;
}
['static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,\n                        X509 *x, X509 *xca, EVP_PKEY *pkey,\n                        STACK_OF(OPENSSL_STRING) *sigopts,\n                        char *serialfile, int create,\n                        int days, int clrext, CONF *conf, char *section,\n                        ASN1_INTEGER *sno, int reqfile)\n{\n    int ret = 0;\n    ASN1_INTEGER *bs = NULL;\n    X509_STORE_CTX xsc;\n    EVP_PKEY *upkey;\n    upkey = X509_get0_pubkey(xca);\n    EVP_PKEY_copy_parameters(upkey, pkey);\n    if (!X509_STORE_CTX_init(&xsc, ctx, x, NULL)) {\n        BIO_printf(bio_err, "Error initialising X509 store\\n");\n        goto end;\n    }\n    if (sno)\n        bs = sno;\n    else if ((bs = x509_load_serial(CAfile, serialfile, create)) == NULL)\n        goto end;\n    X509_STORE_CTX_set_cert(&xsc, x);\n    X509_STORE_CTX_set_flags(&xsc, X509_V_FLAG_CHECK_SS_SIGNATURE);\n    if (!reqfile && X509_verify_cert(&xsc) <= 0)\n        goto end;\n    if (!X509_check_private_key(xca, pkey)) {\n        BIO_printf(bio_err,\n                   "CA certificate and CA private key do not match\\n");\n        goto end;\n    }\n    if (!X509_set_issuer_name(x, X509_get_subject_name(xca)))\n        goto end;\n    if (!X509_set_serialNumber(x, bs))\n        goto end;\n    if (X509_gmtime_adj(X509_get_notBefore(x), 0L) == NULL)\n        goto end;\n    if (X509_time_adj_ex(X509_get_notAfter(x), days, 0, NULL) == NULL)\n        goto end;\n    if (clrext) {\n        while (X509_get_ext_count(x) > 0)\n            X509_delete_ext(x, 0);\n    }\n    if (conf) {\n        X509V3_CTX ctx2;\n#ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL\n        X509_set_version(x, force_version);\n#else\n        X509_set_version(x, 2);\n#endif\n        X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);\n        X509V3_set_nconf(&ctx2, conf);\n        if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x))\n            goto end;\n    }\n    if (!do_X509_sign(x, pkey, digest, sigopts))\n        goto end;\n    ret = 1;\n end:\n    X509_STORE_CTX_cleanup(&xsc);\n    if (!ret)\n        ERR_print_errors(bio_err);\n    if (!sno)\n        ASN1_INTEGER_free(bs);\n    return ret;\n}', 'EVP_PKEY *X509_get0_pubkey(X509 *x)\n{\n    if (x == NULL)\n        return NULL;\n    return X509_PUBKEY_get0(x->cert_info.key);\n}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n    EVP_PKEY *ret = NULL;\n    if (key == NULL)\n        goto error;\n    if (key->pkey != NULL)\n        return key->pkey;\n    if (key->public_key == NULL)\n        goto error;\n    if ((ret = EVP_PKEY_new()) == NULL) {\n        X509err(X509_F_X509_PUBKEY_GET0, ERR_R_MALLOC_FAILURE);\n        goto error;\n    }\n    if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) {\n        X509err(X509_F_X509_PUBKEY_GET0, X509_R_UNSUPPORTED_ALGORITHM);\n        goto error;\n    }\n    if (ret->ameth->pub_decode) {\n        if (!ret->ameth->pub_decode(ret, key)) {\n            X509err(X509_F_X509_PUBKEY_GET0, X509_R_PUBLIC_KEY_DECODE_ERROR);\n            goto error;\n        }\n    } else {\n        X509err(X509_F_X509_PUBKEY_GET0, X509_R_METHOD_NOT_SUPPORTED);\n        goto error;\n    }\n    CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY);\n    if (key->pkey) {\n        CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);\n        EVP_PKEY_free(ret);\n        ret = key->pkey;\n    } else {\n        key->pkey = ret;\n        CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);\n    }\n    return ret;\n error:\n    EVP_PKEY_free(ret);\n    return (NULL);\n}', 'void EVP_PKEY_free(EVP_PKEY *x)\n{\n    int i;\n    if (x == NULL)\n        return;\n    i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY);\n#ifdef REF_PRINT\n    REF_PRINT("EVP_PKEY", x);\n#endif\n    if (i > 0)\n        return;\n#ifdef REF_CHECK\n    if (i < 0) {\n        fprintf(stderr, "EVP_PKEY_free, bad reference count\\n");\n        abort();\n    }\n#endif\n    EVP_PKEY_free_it(x);\n    sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);\n    OPENSSL_free(x);\n}']