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


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

ssl/t1_lib.c:2280:9: Taking true branch
2278.   int tls_choose_sigalg(SSL *s)
2279.   {
2280.       if (SSL_IS_TLS13(s)) {
                ^
2281.           size_t i;
2282.           int curve = -1;

ssl/t1_lib.c:2280:9: Taking true branch
2278.   int tls_choose_sigalg(SSL *s)
2279.   {
2280.       if (SSL_IS_TLS13(s)) {
                ^
2281.           size_t i;
2282.           int curve = -1;

ssl/t1_lib.c:2280:9: Taking true branch
2278.   int tls_choose_sigalg(SSL *s)
2279.   {
2280.       if (SSL_IS_TLS13(s)) {
                ^
2281.           size_t i;
2282.           int curve = -1;

ssl/t1_lib.c:2282:9: 
2280.       if (SSL_IS_TLS13(s)) {
2281.           size_t i;
2282. >         int curve = -1;
2283.   
2284.           /* Look for a certificate matching shared sigaglgs */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ssl/t1_lib.c:2307:17: Taking true branch
2305.                       continue;
2306.               }
2307.               if (lu->sig == EVP_PKEY_EC) {
                        ^
2308.                   if (curve == -1) {
2309.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);

ssl/t1_lib.c:2308:21: Taking true branch
2306.               }
2307.               if (lu->sig == EVP_PKEY_EC) {
2308.                   if (curve == -1) {
                            ^
2309.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
2310.   

ssl/t1_lib.c:2309:21: 
2307.               if (lu->sig == EVP_PKEY_EC) {
2308.                   if (curve == -1) {
2309. >                     EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
2310.   
2311.                       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:2311:21: 
2309.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(c->privatekey);
2310.   
2311. >                     curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
2312.                   }
2313.                   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;
        int curve = -1;
        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) {
                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;
            }
            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        int curve = -1;\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                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            }\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}']