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


ssl/t1_lib.c:2271:1: start of procedure tls_choose_sigalg()
2269.    * Set current certificate and digest to match chosen algorithm.
2270.    */
2271. > int tls_choose_sigalg(SSL *s)
2272.   {
2273.       if (SSL_IS_TLS13(s)) {

ssl/t1_lib.c:2273:9: Taking true branch
2271.   int tls_choose_sigalg(SSL *s)
2272.   {
2273.       if (SSL_IS_TLS13(s)) {
                ^
2274.           size_t i;
2275.   #ifndef OPENSSL_NO_EC

ssl/t1_lib.c:2273:9: Taking true branch
2271.   int tls_choose_sigalg(SSL *s)
2272.   {
2273.       if (SSL_IS_TLS13(s)) {
                ^
2274.           size_t i;
2275.   #ifndef OPENSSL_NO_EC

ssl/t1_lib.c:2273:9: Taking true branch
2271.   int tls_choose_sigalg(SSL *s)
2272.   {
2273.       if (SSL_IS_TLS13(s)) {
                ^
2274.           size_t i;
2275.   #ifndef OPENSSL_NO_EC

ssl/t1_lib.c:2276:9: 
2274.           size_t i;
2275.   #ifndef OPENSSL_NO_EC
2276. >         int curve = -1;
2277.   #endif
2278.   

ssl/t1_lib.c:2280:14: 
2278.   
2279.           /* Look for a certificate matching shared sigaglgs */
2280. >         for (i = 0; i < s->cert->shared_sigalgslen; i++) {
2281.               const SIGALG_LOOKUP *lu = s->cert->shared_sigalgs[i];
2282.               int idx;

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

ssl/t1_lib.c:2281:13: 
2279.           /* Look for a certificate matching shared sigaglgs */
2280.           for (i = 0; i < s->cert->shared_sigalgslen; i++) {
2281. >             const SIGALG_LOOKUP *lu = s->cert->shared_sigalgs[i];
2282.               int idx;
2283.               const EVP_MD *md;

ssl/t1_lib.c:2287:17: Taking false branch
2285.   
2286.               /* Skip RSA if not PSS */
2287.               if (lu->sig == EVP_PKEY_RSA)
                        ^
2288.                   continue;
2289.               md = ssl_md(lu->hash_idx);

ssl/t1_lib.c:2289:13: 
2287.               if (lu->sig == EVP_PKEY_RSA)
2288.                   continue;
2289. >             md = ssl_md(lu->hash_idx);
2290.               if (md == NULL)
2291.                   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:2290:17: Taking false branch
2288.                   continue;
2289.               md = ssl_md(lu->hash_idx);
2290.               if (md == NULL)
                        ^
2291.                   continue;
2292.               idx = lu->sig_idx;

ssl/t1_lib.c:2292:13: 
2290.               if (md == NULL)
2291.                   continue;
2292. >             idx = lu->sig_idx;
2293.               c = &s->cert->pkeys[idx];
2294.               if (c->x509 == NULL || c->privatekey == NULL)

ssl/t1_lib.c:2293:13: 
2291.                   continue;
2292.               idx = lu->sig_idx;
2293. >             c = &s->cert->pkeys[idx];
2294.               if (c->x509 == NULL || c->privatekey == NULL)
2295.                       continue;

ssl/t1_lib.c:2294:17: Taking false branch
2292.               idx = lu->sig_idx;
2293.               c = &s->cert->pkeys[idx];
2294.               if (c->x509 == NULL || c->privatekey == NULL)
                        ^
2295.                       continue;
2296.               if (lu->sig == EVP_PKEY_EC) {

ssl/t1_lib.c:2294:36: Taking false branch
2292.               idx = lu->sig_idx;
2293.               c = &s->cert->pkeys[idx];
2294.               if (c->x509 == NULL || c->privatekey == NULL)
                                           ^
2295.                       continue;
2296.               if (lu->sig == EVP_PKEY_EC) {

ssl/t1_lib.c:2296:17: Taking true branch
2294.               if (c->x509 == NULL || c->privatekey == NULL)
2295.                       continue;
2296.               if (lu->sig == EVP_PKEY_EC) {
                        ^
2297.   #ifndef OPENSSL_NO_EC
2298.                   if (curve == -1) {

ssl/t1_lib.c:2298:21: Taking true branch
2296.               if (lu->sig == EVP_PKEY_EC) {
2297.   #ifndef OPENSSL_NO_EC
2298.                   if (curve == -1) {
                            ^
2299.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
2300.   

ssl/t1_lib.c:2299:21: 
2297.   #ifndef OPENSSL_NO_EC
2298.                   if (curve == -1) {
2299. >                     EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
2300.   
2301.                       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:2301:21: 
2299.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
2300.   
2301. >                     curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
2302.                   }
2303.                   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)
                    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                    continue;\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}']