ssl/t1_lib.c:2315: error: NULL_DEREFERENCE
  pointer `ec` last assigned on line 2313 could be null and is dereferenced by call to `EC_KEY_get0_group()` at line 2315, column 53.
Showing all 32 steps of the trace


ssl/t1_lib.c:2279:1: start of procedure tls_choose_sigalg()
2277.    * Set current certificate and digest to match chosen algorithm.
2278.    */
2279. > int tls_choose_sigalg(SSL *s)
2280.   {
2281.       if (SSL_IS_TLS13(s)) {

ssl/t1_lib.c:2281:9: Taking true branch
2279.   int tls_choose_sigalg(SSL *s)
2280.   {
2281.       if (SSL_IS_TLS13(s)) {
                ^
2282.           size_t i;
2283.   #ifndef OPENSSL_NO_EC

ssl/t1_lib.c:2281:9: Taking true branch
2279.   int tls_choose_sigalg(SSL *s)
2280.   {
2281.       if (SSL_IS_TLS13(s)) {
                ^
2282.           size_t i;
2283.   #ifndef OPENSSL_NO_EC

ssl/t1_lib.c:2281:9: Taking true branch
2279.   int tls_choose_sigalg(SSL *s)
2280.   {
2281.       if (SSL_IS_TLS13(s)) {
                ^
2282.           size_t i;
2283.   #ifndef OPENSSL_NO_EC

ssl/t1_lib.c:2284:9: 
2282.           size_t i;
2283.   #ifndef OPENSSL_NO_EC
2284. >         int curve = -1;
2285.   #endif
2286.   

ssl/t1_lib.c:2288:14: 
2286.   
2287.           /* Look for a certificate matching shared sigaglgs */
2288. >         for (i = 0; i < s->cert->shared_sigalgslen; i++) {
2289.               const SIGALG_LOOKUP *lu = s->cert->shared_sigalgs[i];
2290.               int idx;

ssl/t1_lib.c:2288:21: Loop condition is true. Entering loop body
2286.   
2287.           /* Look for a certificate matching shared sigaglgs */
2288.           for (i = 0; i < s->cert->shared_sigalgslen; i++) {
                            ^
2289.               const SIGALG_LOOKUP *lu = s->cert->shared_sigalgs[i];
2290.               int idx;

ssl/t1_lib.c:2289:13: 
2287.           /* Look for a certificate matching shared sigaglgs */
2288.           for (i = 0; i < s->cert->shared_sigalgslen; i++) {
2289. >             const SIGALG_LOOKUP *lu = s->cert->shared_sigalgs[i];
2290.               int idx;
2291.               const EVP_MD *md;

ssl/t1_lib.c:2295:17: Taking false branch
2293.   
2294.               /* Skip RSA if not PSS */
2295.               if (lu->sig == EVP_PKEY_RSA)
                        ^
2296.                   continue;
2297.               md = ssl_md(lu->hash_idx);

ssl/t1_lib.c:2297:13: 
2295.               if (lu->sig == EVP_PKEY_RSA)
2296.                   continue;
2297. >             md = ssl_md(lu->hash_idx);
2298.               if (md == NULL)
2299.                   continue;

ssl/ssl_ciph.c:611:1: start of procedure ssl_md()
  609.   }
  610.   
  611. > const EVP_MD *ssl_md(int idx)
  612.   {
  613.       idx &= SSL_HANDSHAKE_MAC_MASK;

ssl/ssl_ciph.c:613:5: 
  611.   const EVP_MD *ssl_md(int idx)
  612.   {
  613. >     idx &= SSL_HANDSHAKE_MAC_MASK;
  614.       if (idx < 0 || idx >= SSL_MD_NUM_IDX)
  615.           return NULL;

ssl/ssl_ciph.c:614:9: Taking false branch
  612.   {
  613.       idx &= SSL_HANDSHAKE_MAC_MASK;
  614.       if (idx < 0 || idx >= SSL_MD_NUM_IDX)
                 ^
  615.           return NULL;
  616.       return ssl_digest_methods[idx];

ssl/ssl_ciph.c:614:20: Taking false branch
  612.   {
  613.       idx &= SSL_HANDSHAKE_MAC_MASK;
  614.       if (idx < 0 || idx >= SSL_MD_NUM_IDX)
                            ^
  615.           return NULL;
  616.       return ssl_digest_methods[idx];

ssl/ssl_ciph.c:616:5: 
  614.       if (idx < 0 || idx >= SSL_MD_NUM_IDX)
  615.           return NULL;
  616. >     return ssl_digest_methods[idx];
  617.   }
  618.   

ssl/ssl_ciph.c:617:1: return from a call to ssl_md
  615.           return NULL;
  616.       return ssl_digest_methods[idx];
  617. > }
  618.   
  619.   const EVP_MD *ssl_handshake_md(SSL *s)

ssl/t1_lib.c:2298:17: Taking false branch
2296.                   continue;
2297.               md = ssl_md(lu->hash_idx);
2298.               if (md == NULL)
                        ^
2299.                   continue;
2300.               idx = lu->sig_idx;

ssl/t1_lib.c:2300:13: 
2298.               if (md == NULL)
2299.                   continue;
2300. >             idx = lu->sig_idx;
2301.               c = &s->cert->pkeys[idx];
2302.               if (c->x509 == NULL || c->privatekey == NULL) {

ssl/t1_lib.c:2301:13: 
2299.                   continue;
2300.               idx = lu->sig_idx;
2301. >             c = &s->cert->pkeys[idx];
2302.               if (c->x509 == NULL || c->privatekey == NULL) {
2303.                   if (idx != SSL_PKEY_RSA_SIGN)

ssl/t1_lib.c:2302:17: Taking false branch
2300.               idx = lu->sig_idx;
2301.               c = &s->cert->pkeys[idx];
2302.               if (c->x509 == NULL || c->privatekey == NULL) {
                        ^
2303.                   if (idx != SSL_PKEY_RSA_SIGN)
2304.                       continue;

ssl/t1_lib.c:2302:36: Taking false branch
2300.               idx = lu->sig_idx;
2301.               c = &s->cert->pkeys[idx];
2302.               if (c->x509 == NULL || c->privatekey == NULL) {
                                           ^
2303.                   if (idx != SSL_PKEY_RSA_SIGN)
2304.                       continue;

ssl/t1_lib.c:2310:17: Taking true branch
2308.                       continue;
2309.               }
2310.               if (lu->sig == EVP_PKEY_EC) {
                        ^
2311.   #ifndef OPENSSL_NO_EC
2312.                   if (curve == -1) {

ssl/t1_lib.c:2312:21: Taking true branch
2310.               if (lu->sig == EVP_PKEY_EC) {
2311.   #ifndef OPENSSL_NO_EC
2312.                   if (curve == -1) {
                            ^
2313.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
2314.   

ssl/t1_lib.c:2313:21: 
2311.   #ifndef OPENSSL_NO_EC
2312.                   if (curve == -1) {
2313. >                     EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
2314.   
2315.                       curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));

crypto/evp/p_lib.c:345:1: start of procedure EVP_PKEY_get0_EC_KEY()
  343.   }
  344.   
  345. > EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
  346.   {
  347.       if (pkey->type != EVP_PKEY_EC) {

crypto/evp/p_lib.c:347:9: Taking true branch
  345.   EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
  346.   {
  347.       if (pkey->type != EVP_PKEY_EC) {
                 ^
  348.           EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
  349.           return NULL;

crypto/evp/p_lib.c:348:9: Skipping ERR_put_error(): empty list of specs
  346.   {
  347.       if (pkey->type != EVP_PKEY_EC) {
  348.           EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
                 ^
  349.           return NULL;
  350.       }

crypto/evp/p_lib.c:349:9: 
  347.       if (pkey->type != EVP_PKEY_EC) {
  348.           EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
  349. >         return NULL;
  350.       }
  351.       return pkey->pkey.ec;

crypto/evp/p_lib.c:352:1: return from a call to EVP_PKEY_get0_EC_KEY
  350.       }
  351.       return pkey->pkey.ec;
  352. > }
  353.   
  354.   EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)

ssl/t1_lib.c:2315:21: 
2313.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
2314.   
2315. >                     curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
2316.                   }
2317.                   if (curve != lu->curve)

crypto/ec/ec_key.c:419:1: start of procedure EC_KEY_get0_group()
  417.   }
  418.   
  419. > const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
  420.   {
  421.       return key->group;

crypto/ec/ec_key.c:421:5: 
  419.   const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
  420.   {
  421. >     return key->group;
  422.   }
  423.   

int tls_choose_sigalg(SSL *s)
{
    if (SSL_IS_TLS13(s)) {
        size_t i;
#ifndef OPENSSL_NO_EC
        int curve = -1;
#endif
        for (i = 0; i < s->cert->shared_sigalgslen; i++) {
            const SIGALG_LOOKUP *lu = s->cert->shared_sigalgs[i];
            int idx;
            const EVP_MD *md;
            CERT_PKEY *c;
            if (lu->sig == EVP_PKEY_RSA)
                continue;
            md = ssl_md(lu->hash_idx);
            if (md == NULL)
                continue;
            idx = lu->sig_idx;
            c = &s->cert->pkeys[idx];
            if (c->x509 == NULL || c->privatekey == NULL) {
                if (idx != SSL_PKEY_RSA_SIGN)
                    continue;
                idx = SSL_PKEY_RSA_ENC;
                c = s->cert->pkeys + idx;
                if (c->x509 == NULL || c->privatekey == NULL)
                    continue;
            }
            if (lu->sig == EVP_PKEY_EC) {
#ifndef OPENSSL_NO_EC
                if (curve == -1) {
                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
                }
                if (curve != lu->curve)
                    continue;
#else
                continue;
#endif
            }
            s->s3->tmp.sigalg = lu;
            s->s3->tmp.cert_idx = idx;
            s->s3->tmp.md[idx] = md;
            s->cert->key = s->cert->pkeys + idx;
            return 1;
        }
        return 0;
    }
    return 1;
}
['int tls_choose_sigalg(SSL *s)\n{\n    if (SSL_IS_TLS13(s)) {\n        size_t i;\n#ifndef OPENSSL_NO_EC\n        int curve = -1;\n#endif\n        for (i = 0; i < s->cert->shared_sigalgslen; i++) {\n            const SIGALG_LOOKUP *lu = s->cert->shared_sigalgs[i];\n            int idx;\n            const EVP_MD *md;\n            CERT_PKEY *c;\n            if (lu->sig == EVP_PKEY_RSA)\n                continue;\n            md = ssl_md(lu->hash_idx);\n            if (md == NULL)\n                continue;\n            idx = lu->sig_idx;\n            c = &s->cert->pkeys[idx];\n            if (c->x509 == NULL || c->privatekey == NULL) {\n                if (idx != SSL_PKEY_RSA_SIGN)\n                    continue;\n                idx = SSL_PKEY_RSA_ENC;\n                c = s->cert->pkeys + idx;\n                if (c->x509 == NULL || c->privatekey == NULL)\n                    continue;\n            }\n            if (lu->sig == EVP_PKEY_EC) {\n#ifndef OPENSSL_NO_EC\n                if (curve == -1) {\n                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);\n                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));\n                }\n                if (curve != lu->curve)\n                    continue;\n#else\n                continue;\n#endif\n            }\n            s->s3->tmp.sigalg = lu;\n            s->s3->tmp.cert_idx = idx;\n            s->s3->tmp.md[idx] = md;\n            s->cert->key = s->cert->pkeys + idx;\n            return 1;\n        }\n        return 0;\n    }\n    return 1;\n}', 'const EVP_MD *ssl_md(int idx)\n{\n    idx &= SSL_HANDSHAKE_MAC_MASK;\n    if (idx < 0 || idx >= SSL_MD_NUM_IDX)\n        return NULL;\n    return ssl_digest_methods[idx];\n}', 'EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)\n{\n    if (pkey->type != EVP_PKEY_EC) {\n        EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);\n        return NULL;\n    }\n    return pkey->pkey.ec;\n}', 'const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)\n{\n    return key->group;\n}']