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


ssl/t1_lib.c:2280:1: start of procedure tls_choose_sigalg()
2278.    * to the server. In this case no error is set.
2279.    */
2280. > int tls_choose_sigalg(SSL *s, int fatalerrs)
2281.   {
2282.       const SIGALG_LOOKUP *lu = NULL;

ssl/t1_lib.c:2282:5: 
2280.   int tls_choose_sigalg(SSL *s, int fatalerrs)
2281.   {
2282. >     const SIGALG_LOOKUP *lu = NULL;
2283.       int sig_idx = -1;
2284.   

ssl/t1_lib.c:2283:5: 
2281.   {
2282.       const SIGALG_LOOKUP *lu = NULL;
2283. >     int sig_idx = -1;
2284.   
2285.       s->s3->tmp.cert = NULL;

ssl/t1_lib.c:2285:5: 
2283.       int sig_idx = -1;
2284.   
2285. >     s->s3->tmp.cert = NULL;
2286.       s->s3->tmp.sigalg = NULL;
2287.   

ssl/t1_lib.c:2286:5: 
2284.   
2285.       s->s3->tmp.cert = NULL;
2286. >     s->s3->tmp.sigalg = NULL;
2287.   
2288.       if (SSL_IS_TLS13(s)) {

ssl/t1_lib.c:2288:9: Taking false branch
2286.       s->s3->tmp.sigalg = NULL;
2287.   
2288.       if (SSL_IS_TLS13(s)) {
                ^
2289.           size_t i;
2290.   #ifndef OPENSSL_NO_EC

ssl/t1_lib.c:2360:15: Taking false branch
2358.       } else {
2359.           /* If ciphersuite doesn't require a cert nothing to do */
2360.           if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aCERT))
                      ^
2361.               return 1;
2362.           if (!s->server && !ssl_has_cert(s, s->cert->key - s->cert->pkeys))

ssl/t1_lib.c:2362:14: Taking true branch
2360.           if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aCERT))
2361.               return 1;
2362.           if (!s->server && !ssl_has_cert(s, s->cert->key - s->cert->pkeys))
                     ^
2363.                   return 1;
2364.   

ssl/t1_lib.c:2362:28: 
2360.           if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aCERT))
2361.               return 1;
2362. >         if (!s->server && !ssl_has_cert(s, s->cert->key - s->cert->pkeys))
2363.                   return 1;
2364.   

ssl/ssl_locl.h:2125:1: start of procedure ssl_has_cert()
  2123.   
  2124.   /* Returns true if certificate and private key for 'idx' are present */
  2125. > static ossl_inline int ssl_has_cert(const SSL *s, int idx)
  2126.   {
  2127.       if (idx < 0 || idx >= SSL_PKEY_NUM)

ssl/ssl_locl.h:2127:9: Taking false branch
  2125.   static ossl_inline int ssl_has_cert(const SSL *s, int idx)
  2126.   {
  2127.       if (idx < 0 || idx >= SSL_PKEY_NUM)
                  ^
  2128.           return 0;
  2129.       return s->cert->pkeys[idx].x509 != NULL

ssl/ssl_locl.h:2127:20: Taking false branch
  2125.   static ossl_inline int ssl_has_cert(const SSL *s, int idx)
  2126.   {
  2127.       if (idx < 0 || idx >= SSL_PKEY_NUM)
                             ^
  2128.           return 0;
  2129.       return s->cert->pkeys[idx].x509 != NULL

ssl/ssl_locl.h:2129:12: Condition is true
  2127.       if (idx < 0 || idx >= SSL_PKEY_NUM)
  2128.           return 0;
  2129.       return s->cert->pkeys[idx].x509 != NULL
                     ^
  2130.           && s->cert->pkeys[idx].privatekey != NULL;
  2131.   }

ssl/ssl_locl.h:2130:12: Condition is true
  2128.           return 0;
  2129.       return s->cert->pkeys[idx].x509 != NULL
  2130.           && s->cert->pkeys[idx].privatekey != NULL;
                     ^
  2131.   }
  2132.   

ssl/ssl_locl.h:2129:12: 
  2127.       if (idx < 0 || idx >= SSL_PKEY_NUM)
  2128.           return 0;
  2129. >     return s->cert->pkeys[idx].x509 != NULL
  2130.           && s->cert->pkeys[idx].privatekey != NULL;
  2131.   }

ssl/ssl_locl.h:2129:5: 
  2127.       if (idx < 0 || idx >= SSL_PKEY_NUM)
  2128.           return 0;
  2129. >     return s->cert->pkeys[idx].x509 != NULL
  2130.           && s->cert->pkeys[idx].privatekey != NULL;
  2131.   }

ssl/ssl_locl.h:2131:1: return from a call to ssl_has_cert
  2129.       return s->cert->pkeys[idx].x509 != NULL
  2130.           && s->cert->pkeys[idx].privatekey != NULL;
  2131. > }
  2132.   
  2133.   static ossl_inline void tls1_get_peer_groups(SSL *s, const uint16_t **pgroups,

ssl/t1_lib.c:2362:28: Taking false branch
2360.           if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aCERT))
2361.               return 1;
2362.           if (!s->server && !ssl_has_cert(s, s->cert->key - s->cert->pkeys))
                                   ^
2363.                   return 1;
2364.   

ssl/t1_lib.c:2365:13: Taking true branch
2363.                   return 1;
2364.   
2365.           if (SSL_USE_SIGALGS(s)) {
                    ^
2366.               if (s->s3->tmp.peer_sigalgs != NULL) {
2367.                   size_t i;

ssl/t1_lib.c:2366:17: Taking true branch
2364.   
2365.           if (SSL_USE_SIGALGS(s)) {
2366.               if (s->s3->tmp.peer_sigalgs != NULL) {
                        ^
2367.                   size_t i;
2368.   #ifndef OPENSSL_NO_EC

ssl/t1_lib.c:2372:21: Taking true branch
2370.   
2371.                   /* For Suite B need to match signature algorithm to curve */
2372.                   if (tls1_suiteb(s)) {
                            ^
2373.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[SSL_PKEY_ECC].privatekey);
2374.                       curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));

ssl/t1_lib.c:2373:21: 
2371.                   /* For Suite B need to match signature algorithm to curve */
2372.                   if (tls1_suiteb(s)) {
2373. >                     EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[SSL_PKEY_ECC].privatekey);
2374.                       curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
2375.                   } else {

crypto/evp/p_lib.c:366:1: start of procedure EVP_PKEY_get0_EC_KEY()
  364.   }
  365.   
  366. > EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
  367.   {
  368.       if (pkey->type != EVP_PKEY_EC) {

crypto/evp/p_lib.c:368:9: Taking true branch
  366.   EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
  367.   {
  368.       if (pkey->type != EVP_PKEY_EC) {
                 ^
  369.           EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
  370.           return NULL;

crypto/evp/p_lib.c:369:9: Skipping ERR_put_error(): empty list of specs
  367.   {
  368.       if (pkey->type != EVP_PKEY_EC) {
  369.           EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
                 ^
  370.           return NULL;
  371.       }

crypto/evp/p_lib.c:370:9: 
  368.       if (pkey->type != EVP_PKEY_EC) {
  369.           EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
  370. >         return NULL;
  371.       }
  372.       return pkey->pkey.ec;

crypto/evp/p_lib.c:373:1: return from a call to EVP_PKEY_get0_EC_KEY
  371.       }
  372.       return pkey->pkey.ec;
  373. > }
  374.   
  375.   EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)

ssl/t1_lib.c:2374:21: 
2372.                   if (tls1_suiteb(s)) {
2373.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[SSL_PKEY_ECC].privatekey);
2374. >                     curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
2375.                   } else {
2376.                       curve = -1;

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, int fatalerrs)
{
    const SIGALG_LOOKUP *lu = NULL;
    int sig_idx = -1;
    s->s3->tmp.cert = NULL;
    s->s3->tmp.sigalg = NULL;
    if (SSL_IS_TLS13(s)) {
        size_t i;
#ifndef OPENSSL_NO_EC
        int curve = -1, skip_ec = 0;
#endif
        for (i = 0; i < s->cert->shared_sigalgslen; i++) {
            lu = s->cert->shared_sigalgs[i];
            sig_idx = -1;
            if (lu->hash == NID_sha1
                || lu->hash == NID_sha224
                || lu->sig == EVP_PKEY_DSA
                || lu->sig == EVP_PKEY_RSA)
                continue;
            if (!tls1_lookup_md(lu, NULL))
                continue;
            if (!ssl_has_cert(s, lu->sig_idx)) {
                if (lu->sig_idx != SSL_PKEY_RSA_PSS_SIGN
                        || !ssl_has_cert(s, SSL_PKEY_RSA))
                    continue;
                sig_idx = SSL_PKEY_RSA;
            }
            if (lu->sig == EVP_PKEY_EC) {
#ifndef OPENSSL_NO_EC
                if (curve == -1) {
                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[SSL_PKEY_ECC].privatekey);
                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
                    if (EC_KEY_get_conv_form(ec)
                        != POINT_CONVERSION_UNCOMPRESSED)
                        skip_ec = 1;
                }
                if (skip_ec || (lu->curve != NID_undef && curve != lu->curve))
                    continue;
#else
                continue;
#endif
            } else if (lu->sig == EVP_PKEY_RSA_PSS) {
                EVP_PKEY *pkey;
                int pkey_id;
                if (sig_idx == -1)
                    pkey = s->cert->pkeys[lu->sig_idx].privatekey;
                else
                    pkey = s->cert->pkeys[sig_idx].privatekey;
                pkey_id = EVP_PKEY_id(pkey);
                if (pkey_id != EVP_PKEY_RSA_PSS
                    && pkey_id != EVP_PKEY_RSA)
                    continue;
                if (!rsa_pss_check_min_key_size(EVP_PKEY_get0(pkey), lu))
                    continue;
            }
            break;
        }
        if (i == s->cert->shared_sigalgslen) {
            if (!fatalerrs)
                return 1;
            SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, SSL_F_TLS_CHOOSE_SIGALG,
                     SSL_R_NO_SUITABLE_SIGNATURE_ALGORITHM);
            return 0;
        }
    } else {
        if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aCERT))
            return 1;
        if (!s->server && !ssl_has_cert(s, s->cert->key - s->cert->pkeys))
                return 1;
        if (SSL_USE_SIGALGS(s)) {
            if (s->s3->tmp.peer_sigalgs != NULL) {
                size_t i;
#ifndef OPENSSL_NO_EC
                int curve;
                if (tls1_suiteb(s)) {
                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[SSL_PKEY_ECC].privatekey);
                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
                } else {
                    curve = -1;
                }
#endif
                for (i = 0; i < s->cert->shared_sigalgslen; i++) {
                    lu = s->cert->shared_sigalgs[i];
                    if (s->server) {
                        if ((sig_idx = tls12_get_cert_sigalg_idx(s, lu)) == -1)
                            continue;
                    } else {
                        int cc_idx = s->cert->key - s->cert->pkeys;
                        sig_idx = lu->sig_idx;
                        if (cc_idx != sig_idx) {
                            if (sig_idx != SSL_PKEY_RSA_PSS_SIGN
                                || cc_idx != SSL_PKEY_RSA)
                                continue;
                            sig_idx = SSL_PKEY_RSA;
                        }
                    }
                    if (lu->sig == EVP_PKEY_RSA_PSS) {
                        EVP_PKEY *pkey = s->cert->pkeys[sig_idx].privatekey;
                        int pkey_id = EVP_PKEY_id(pkey);
                        if (pkey_id != EVP_PKEY_RSA_PSS
                            && pkey_id != EVP_PKEY_RSA)
                            continue;
                        if (!rsa_pss_check_min_key_size(EVP_PKEY_get0(pkey), lu))
                            continue;
                    }
#ifndef OPENSSL_NO_EC
                    if (curve == -1 || lu->curve == curve)
#endif
                        break;
                }
                if (i == s->cert->shared_sigalgslen) {
                    if (!fatalerrs)
                        return 1;
                    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CHOOSE_SIGALG,
                             ERR_R_INTERNAL_ERROR);
                    return 0;
                }
            } else {
                const uint16_t *sent_sigs;
                size_t sent_sigslen, i;
                if ((lu = tls1_get_legacy_sigalg(s, -1)) == NULL) {
                    if (!fatalerrs)
                        return 1;
                    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CHOOSE_SIGALG,
                             ERR_R_INTERNAL_ERROR);
                    return 0;
                }
                sent_sigslen = tls12_get_psigalgs(s, 1, &sent_sigs);
                for (i = 0; i < sent_sigslen; i++, sent_sigs++) {
                    if (lu->sigalg == *sent_sigs)
                        break;
                }
                if (i == sent_sigslen) {
                    if (!fatalerrs)
                        return 1;
                    SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER,
                             SSL_F_TLS_CHOOSE_SIGALG,
                             SSL_R_WRONG_SIGNATURE_TYPE);
                    return 0;
                }
            }
        } else {
            if ((lu = tls1_get_legacy_sigalg(s, -1)) == NULL) {
                if (!fatalerrs)
                    return 1;
                SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CHOOSE_SIGALG,
                         ERR_R_INTERNAL_ERROR);
                return 0;
            }
        }
    }
    if (sig_idx == -1)
        sig_idx = lu->sig_idx;
    s->s3->tmp.cert = &s->cert->pkeys[sig_idx];
    s->cert->key = s->s3->tmp.cert;
    s->s3->tmp.sigalg = lu;
    return 1;
}
['int tls_choose_sigalg(SSL *s, int fatalerrs)\n{\n    const SIGALG_LOOKUP *lu = NULL;\n    int sig_idx = -1;\n    s->s3->tmp.cert = NULL;\n    s->s3->tmp.sigalg = NULL;\n    if (SSL_IS_TLS13(s)) {\n        size_t i;\n#ifndef OPENSSL_NO_EC\n        int curve = -1, skip_ec = 0;\n#endif\n        for (i = 0; i < s->cert->shared_sigalgslen; i++) {\n            lu = s->cert->shared_sigalgs[i];\n            sig_idx = -1;\n            if (lu->hash == NID_sha1\n                || lu->hash == NID_sha224\n                || lu->sig == EVP_PKEY_DSA\n                || lu->sig == EVP_PKEY_RSA)\n                continue;\n            if (!tls1_lookup_md(lu, NULL))\n                continue;\n            if (!ssl_has_cert(s, lu->sig_idx)) {\n                if (lu->sig_idx != SSL_PKEY_RSA_PSS_SIGN\n                        || !ssl_has_cert(s, SSL_PKEY_RSA))\n                    continue;\n                sig_idx = SSL_PKEY_RSA;\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(s->cert->pkeys[SSL_PKEY_ECC].privatekey);\n                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));\n                    if (EC_KEY_get_conv_form(ec)\n                        != POINT_CONVERSION_UNCOMPRESSED)\n                        skip_ec = 1;\n                }\n                if (skip_ec || (lu->curve != NID_undef && curve != lu->curve))\n                    continue;\n#else\n                continue;\n#endif\n            } else if (lu->sig == EVP_PKEY_RSA_PSS) {\n                EVP_PKEY *pkey;\n                int pkey_id;\n                if (sig_idx == -1)\n                    pkey = s->cert->pkeys[lu->sig_idx].privatekey;\n                else\n                    pkey = s->cert->pkeys[sig_idx].privatekey;\n                pkey_id = EVP_PKEY_id(pkey);\n                if (pkey_id != EVP_PKEY_RSA_PSS\n                    && pkey_id != EVP_PKEY_RSA)\n                    continue;\n                if (!rsa_pss_check_min_key_size(EVP_PKEY_get0(pkey), lu))\n                    continue;\n            }\n            break;\n        }\n        if (i == s->cert->shared_sigalgslen) {\n            if (!fatalerrs)\n                return 1;\n            SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, SSL_F_TLS_CHOOSE_SIGALG,\n                     SSL_R_NO_SUITABLE_SIGNATURE_ALGORITHM);\n            return 0;\n        }\n    } else {\n        if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aCERT))\n            return 1;\n        if (!s->server && !ssl_has_cert(s, s->cert->key - s->cert->pkeys))\n                return 1;\n        if (SSL_USE_SIGALGS(s)) {\n            if (s->s3->tmp.peer_sigalgs != NULL) {\n                size_t i;\n#ifndef OPENSSL_NO_EC\n                int curve;\n                if (tls1_suiteb(s)) {\n                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[SSL_PKEY_ECC].privatekey);\n                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));\n                } else {\n                    curve = -1;\n                }\n#endif\n                for (i = 0; i < s->cert->shared_sigalgslen; i++) {\n                    lu = s->cert->shared_sigalgs[i];\n                    if (s->server) {\n                        if ((sig_idx = tls12_get_cert_sigalg_idx(s, lu)) == -1)\n                            continue;\n                    } else {\n                        int cc_idx = s->cert->key - s->cert->pkeys;\n                        sig_idx = lu->sig_idx;\n                        if (cc_idx != sig_idx) {\n                            if (sig_idx != SSL_PKEY_RSA_PSS_SIGN\n                                || cc_idx != SSL_PKEY_RSA)\n                                continue;\n                            sig_idx = SSL_PKEY_RSA;\n                        }\n                    }\n                    if (lu->sig == EVP_PKEY_RSA_PSS) {\n                        EVP_PKEY *pkey = s->cert->pkeys[sig_idx].privatekey;\n                        int pkey_id = EVP_PKEY_id(pkey);\n                        if (pkey_id != EVP_PKEY_RSA_PSS\n                            && pkey_id != EVP_PKEY_RSA)\n                            continue;\n                        if (!rsa_pss_check_min_key_size(EVP_PKEY_get0(pkey), lu))\n                            continue;\n                    }\n#ifndef OPENSSL_NO_EC\n                    if (curve == -1 || lu->curve == curve)\n#endif\n                        break;\n                }\n                if (i == s->cert->shared_sigalgslen) {\n                    if (!fatalerrs)\n                        return 1;\n                    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CHOOSE_SIGALG,\n                             ERR_R_INTERNAL_ERROR);\n                    return 0;\n                }\n            } else {\n                const uint16_t *sent_sigs;\n                size_t sent_sigslen, i;\n                if ((lu = tls1_get_legacy_sigalg(s, -1)) == NULL) {\n                    if (!fatalerrs)\n                        return 1;\n                    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CHOOSE_SIGALG,\n                             ERR_R_INTERNAL_ERROR);\n                    return 0;\n                }\n                sent_sigslen = tls12_get_psigalgs(s, 1, &sent_sigs);\n                for (i = 0; i < sent_sigslen; i++, sent_sigs++) {\n                    if (lu->sigalg == *sent_sigs)\n                        break;\n                }\n                if (i == sent_sigslen) {\n                    if (!fatalerrs)\n                        return 1;\n                    SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER,\n                             SSL_F_TLS_CHOOSE_SIGALG,\n                             SSL_R_WRONG_SIGNATURE_TYPE);\n                    return 0;\n                }\n            }\n        } else {\n            if ((lu = tls1_get_legacy_sigalg(s, -1)) == NULL) {\n                if (!fatalerrs)\n                    return 1;\n                SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CHOOSE_SIGALG,\n                         ERR_R_INTERNAL_ERROR);\n                return 0;\n            }\n        }\n    }\n    if (sig_idx == -1)\n        sig_idx = lu->sig_idx;\n    s->s3->tmp.cert = &s->cert->pkeys[sig_idx];\n    s->cert->key = s->s3->tmp.cert;\n    s->s3->tmp.sigalg = lu;\n    return 1;\n}', 'static ossl_inline int ssl_has_cert(const SSL *s, int idx)\n{\n    if (idx < 0 || idx >= SSL_PKEY_NUM)\n        return 0;\n    return s->cert->pkeys[idx].x509 != NULL\n        && s->cert->pkeys[idx].privatekey != NULL;\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}']