crypto/x509/x509_cmp.c:406: error: NULL_DEREFERENCE
  pointer `x` last assigned on line 401 could be null and is dereferenced by call to `X509_get_version()` at line 406, column 9.
Showing all 17 steps of the trace


crypto/x509/x509_cmp.c:390:1: start of procedure X509_chain_check_suiteb()
388.   }
389.   
390. > int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain,
391.                               unsigned long flags)
392.   {

crypto/x509/x509_cmp.c:394:5: 
392.   {
393.       int rv, i, sign_nid;
394. >     EVP_PKEY *pk = NULL;
395.       unsigned long tflags;
396.       if (!(flags & X509_V_FLAG_SUITEB_128_LOS))

crypto/x509/x509_cmp.c:396:11: Taking false branch
394.       EVP_PKEY *pk = NULL;
395.       unsigned long tflags;
396.       if (!(flags & X509_V_FLAG_SUITEB_128_LOS))
                 ^
397.           return X509_V_OK;
398.       tflags = flags;

crypto/x509/x509_cmp.c:398:5: 
396.       if (!(flags & X509_V_FLAG_SUITEB_128_LOS))
397.           return X509_V_OK;
398. >     tflags = flags;
399.       /* If no EE certificate passed in must be first in chain */
400.       if (x == NULL) {

crypto/x509/x509_cmp.c:400:9: Taking true branch
398.       tflags = flags;
399.       /* If no EE certificate passed in must be first in chain */
400.       if (x == NULL) {
               ^
401.           x = sk_X509_value(chain, 0);
402.           i = 1;

crypto/x509/x509_cmp.c:401:13: Condition is true
399.       /* If no EE certificate passed in must be first in chain */
400.       if (x == NULL) {
401.           x = sk_X509_value(chain, 0);
                   ^
402.           i = 1;
403.       } else

crypto/x509/x509_cmp.c:401:9: 
399.       /* If no EE certificate passed in must be first in chain */
400.       if (x == NULL) {
401. >         x = sk_X509_value(chain, 0);
402.           i = 1;
403.       } else

crypto/stack/stack.c:324:1: start of procedure sk_value()
  322.   }
  323.   
  324. > void *sk_value(const _STACK *st, int i)
  325.   {
  326.       if (!st || (i < 0) || (i >= st->num))

crypto/stack/stack.c:326:10: Taking false branch
  324.   void *sk_value(const _STACK *st, int i)
  325.   {
  326.       if (!st || (i < 0) || (i >= st->num))
                  ^
  327.           return NULL;
  328.       return st->data[i];

crypto/stack/stack.c:326:17: Taking false branch
  324.   void *sk_value(const _STACK *st, int i)
  325.   {
  326.       if (!st || (i < 0) || (i >= st->num))
                         ^
  327.           return NULL;
  328.       return st->data[i];

crypto/stack/stack.c:326:28: Taking true branch
  324.   void *sk_value(const _STACK *st, int i)
  325.   {
  326.       if (!st || (i < 0) || (i >= st->num))
                                    ^
  327.           return NULL;
  328.       return st->data[i];

crypto/stack/stack.c:327:9: 
  325.   {
  326.       if (!st || (i < 0) || (i >= st->num))
  327. >         return NULL;
  328.       return st->data[i];
  329.   }

crypto/stack/stack.c:329:1: return from a call to sk_value
  327.           return NULL;
  328.       return st->data[i];
  329. > }
  330.   
  331.   void *sk_set(_STACK *st, int i, void *value)

crypto/x509/x509_cmp.c:402:9: 
400.       if (x == NULL) {
401.           x = sk_X509_value(chain, 0);
402. >         i = 1;
403.       } else
404.           i = 0;

crypto/x509/x509_cmp.c:406:9: 
404.           i = 0;
405.   
406. >     if (X509_get_version(x) != 2) {
407.           rv = X509_V_ERR_SUITE_B_INVALID_VERSION;
408.           /* Correct error depth */

crypto/x509/x509_set.c:159:1: start of procedure X509_get_version()
  157.   }
  158.   
  159. > long X509_get_version(X509 *x)
  160.   {
  161.       return ASN1_INTEGER_get(x->cert_info->version);

crypto/x509/x509_set.c:161:5: 
  159.   long X509_get_version(X509 *x)
  160.   {
  161. >     return ASN1_INTEGER_get(x->cert_info->version);
  162.   }
  163.   

int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain,
                            unsigned long flags)
{
    int rv, i, sign_nid;
    EVP_PKEY *pk = NULL;
    unsigned long tflags;
    if (!(flags & X509_V_FLAG_SUITEB_128_LOS))
        return X509_V_OK;
    tflags = flags;
    if (x == NULL) {
        x = sk_X509_value(chain, 0);
        i = 1;
    } else
        i = 0;
    if (X509_get_version(x) != 2) {
        rv = X509_V_ERR_SUITE_B_INVALID_VERSION;
        i = 0;
        goto end;
    }
    pk = X509_get_pubkey(x);
    rv = check_suite_b(pk, -1, &tflags);
    if (rv != X509_V_OK) {
        i = 0;
        goto end;
    }
    for (; i < sk_X509_num(chain); i++) {
        sign_nid = X509_get_signature_nid(x);
        x = sk_X509_value(chain, i);
        if (X509_get_version(x) != 2) {
            rv = X509_V_ERR_SUITE_B_INVALID_VERSION;
            goto end;
        }
        EVP_PKEY_free(pk);
        pk = X509_get_pubkey(x);
        rv = check_suite_b(pk, sign_nid, &tflags);
        if (rv != X509_V_OK)
            goto end;
    }
    rv = check_suite_b(pk, X509_get_signature_nid(x), &tflags);
 end:
    EVP_PKEY_free(pk);
    if (rv != X509_V_OK) {
        if ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM
             || rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED) && i)
            i--;
        if (rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED && flags != tflags)
            rv = X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256;
        if (perror_depth)
            *perror_depth = i;
    }
    return rv;
}
['int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain,\n                            unsigned long flags)\n{\n    int rv, i, sign_nid;\n    EVP_PKEY *pk = NULL;\n    unsigned long tflags;\n    if (!(flags & X509_V_FLAG_SUITEB_128_LOS))\n        return X509_V_OK;\n    tflags = flags;\n    if (x == NULL) {\n        x = sk_X509_value(chain, 0);\n        i = 1;\n    } else\n        i = 0;\n    if (X509_get_version(x) != 2) {\n        rv = X509_V_ERR_SUITE_B_INVALID_VERSION;\n        i = 0;\n        goto end;\n    }\n    pk = X509_get_pubkey(x);\n    rv = check_suite_b(pk, -1, &tflags);\n    if (rv != X509_V_OK) {\n        i = 0;\n        goto end;\n    }\n    for (; i < sk_X509_num(chain); i++) {\n        sign_nid = X509_get_signature_nid(x);\n        x = sk_X509_value(chain, i);\n        if (X509_get_version(x) != 2) {\n            rv = X509_V_ERR_SUITE_B_INVALID_VERSION;\n            goto end;\n        }\n        EVP_PKEY_free(pk);\n        pk = X509_get_pubkey(x);\n        rv = check_suite_b(pk, sign_nid, &tflags);\n        if (rv != X509_V_OK)\n            goto end;\n    }\n    rv = check_suite_b(pk, X509_get_signature_nid(x), &tflags);\n end:\n    EVP_PKEY_free(pk);\n    if (rv != X509_V_OK) {\n        if ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM\n             || rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED) && i)\n            i--;\n        if (rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED && flags != tflags)\n            rv = X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256;\n        if (perror_depth)\n            *perror_depth = i;\n    }\n    return rv;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n    if (!st || (i < 0) || (i >= st->num))\n        return NULL;\n    return st->data[i];\n}', 'long X509_get_version(X509 *x)\n{\n    return ASN1_INTEGER_get(x->cert_info->version);\n}']