crypto/x509/x509_trs.c:146: error: NULL_DEREFERENCE
  pointer `trtmp` last assigned on line 143 could be null and is dereferenced at line 146, column 9.
Showing all 36 steps of the trace


crypto/x509/x509_trs.c:122:1: start of procedure X509_TRUST_add()
120.   }
121.   
122. > int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int),
123.                      const char *name, int arg1, void *arg2)
124.   {

crypto/x509/x509_trs.c:130:5: 
128.        * This is set according to what we change: application can't set it
129.        */
130. >     flags &= ~X509_TRUST_DYNAMIC;
131.       /* This will always be set for application modified trust entries */
132.       flags |= X509_TRUST_DYNAMIC_NAME;

crypto/x509/x509_trs.c:132:5: 
130.       flags &= ~X509_TRUST_DYNAMIC;
131.       /* This will always be set for application modified trust entries */
132. >     flags |= X509_TRUST_DYNAMIC_NAME;
133.       /* Get existing entry if any */
134.       idx = X509_TRUST_get_by_id(id);

crypto/x509/x509_trs.c:134:5: 
132.       flags |= X509_TRUST_DYNAMIC_NAME;
133.       /* Get existing entry if any */
134. >     idx = X509_TRUST_get_by_id(id);
135.       /* Need a new entry */
136.       if (idx == -1) {

crypto/x509/x509_trs.c:97:1: start of procedure X509_TRUST_get_by_id()
  95.   }
  96.   
  97. > int X509_TRUST_get_by_id(int id)
  98.   {
  99.       X509_TRUST tmp;

crypto/x509/x509_trs.c:101:10: Taking true branch
  99.       X509_TRUST tmp;
  100.       int idx;
  101.       if ((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
                  ^
  102.           return id - X509_TRUST_MIN;
  103.       tmp.trust = id;

crypto/x509/x509_trs.c:101:36: Taking false branch
  99.       X509_TRUST tmp;
  100.       int idx;
  101.       if ((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
                                            ^
  102.           return id - X509_TRUST_MIN;
  103.       tmp.trust = id;

crypto/x509/x509_trs.c:103:5: 
  101.       if ((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
  102.           return id - X509_TRUST_MIN;
  103. >     tmp.trust = id;
  104.       if (!trtable)
  105.           return -1;

crypto/x509/x509_trs.c:104:10: Taking false branch
  102.           return id - X509_TRUST_MIN;
  103.       tmp.trust = id;
  104.       if (!trtable)
                  ^
  105.           return -1;
  106.       idx = sk_X509_TRUST_find(trtable, &tmp);

crypto/x509/x509_trs.c:106:5: 
  104.       if (!trtable)
  105.           return -1;
  106. >     idx = sk_X509_TRUST_find(trtable, &tmp);
  107.       if (idx == -1)
  108.           return -1;

include/openssl/x509.h:111:1: start of procedure sk_X509_TRUST_find()
    109.   } X509_TRUST;
    110.   
    111. > DEFINE_STACK_OF(X509_TRUST)
    112.   
    113.   /* standard trust ids */

crypto/stack/stack.c:190:1: start of procedure OPENSSL_sk_find()
      188.   }
      189.   
      190. > int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      191.   {
      192.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);

crypto/stack/stack.c:192:5: 
      190.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      191.   {
      192. >     return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      193.   }
      194.   

crypto/stack/stack.c:165:1: start of procedure internal_find()
        163.   }
        164.   
        165. > static int internal_find(OPENSSL_STACK *st, const void *data,
        166.                            int ret_val_options)
        167.   {

crypto/stack/stack.c:171:9: Taking false branch
        169.       int i;
        170.   
        171.       if (st == NULL)
                       ^
        172.           return -1;
        173.   

crypto/stack/stack.c:174:9: Taking true branch
        172.           return -1;
        173.   
        174.       if (st->comp == NULL) {
                       ^
        175.           for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)

crypto/stack/stack.c:175:14: 
        173.   
        174.       if (st->comp == NULL) {
        175. >         for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
        177.                   return (i);

crypto/stack/stack.c:175:21: Loop condition is true. Entering loop body
        173.   
        174.       if (st->comp == NULL) {
        175.           for (i = 0; i < st->num; i++)
                                   ^
        176.               if (st->data[i] == data)
        177.                   return (i);

crypto/stack/stack.c:176:17: Taking false branch
        174.       if (st->comp == NULL) {
        175.           for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
                               ^
        177.                   return (i);
        178.           return (-1);

crypto/stack/stack.c:175:34: 
        173.   
        174.       if (st->comp == NULL) {
        175. >         for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
        177.                   return (i);

crypto/stack/stack.c:175:21: Loop condition is true. Entering loop body
        173.   
        174.       if (st->comp == NULL) {
        175.           for (i = 0; i < st->num; i++)
                                   ^
        176.               if (st->data[i] == data)
        177.                   return (i);

crypto/stack/stack.c:176:17: Taking true branch
        174.       if (st->comp == NULL) {
        175.           for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
                               ^
        177.                   return (i);
        178.           return (-1);

crypto/stack/stack.c:177:17: 
        175.           for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
        177. >                 return (i);
        178.           return (-1);
        179.       }

crypto/stack/stack.c:188:1: return from a call to internal_find
        186.           return (-1);
        187.       return (int)((const char **)r - st->data);
        188. > }
        189.   
        190.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)

crypto/stack/stack.c:193:1: return from a call to OPENSSL_sk_find
      191.   {
      192.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      193. > }
      194.   
      195.   int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data)

include/openssl/x509.h:111:1: return from a call to sk_X509_TRUST_find
    109.   } X509_TRUST;
    110.   
    111. > DEFINE_STACK_OF(X509_TRUST)
    112.   
    113.   /* standard trust ids */

crypto/x509/x509_trs.c:107:9: Taking false branch
  105.           return -1;
  106.       idx = sk_X509_TRUST_find(trtable, &tmp);
  107.       if (idx == -1)
                 ^
  108.           return -1;
  109.       return idx + X509_TRUST_COUNT;

crypto/x509/x509_trs.c:109:5: 
  107.       if (idx == -1)
  108.           return -1;
  109. >     return idx + X509_TRUST_COUNT;
  110.   }
  111.   

crypto/x509/x509_trs.c:110:1: return from a call to X509_TRUST_get_by_id
  108.           return -1;
  109.       return idx + X509_TRUST_COUNT;
  110. > }
  111.   
  112.   int X509_TRUST_set(int *t, int trust)

crypto/x509/x509_trs.c:136:9: Taking false branch
134.       idx = X509_TRUST_get_by_id(id);
135.       /* Need a new entry */
136.       if (idx == -1) {
               ^
137.           if ((trtmp = OPENSSL_malloc(sizeof(*trtmp))) == NULL) {
138.               X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);

crypto/x509/x509_trs.c:143:9: 
141.           trtmp->flags = X509_TRUST_DYNAMIC;
142.       } else
143. >         trtmp = X509_TRUST_get0(idx);
144.   
145.       /* OPENSSL_free existing name if dynamic */

crypto/x509/x509_trs.c:88:1: start of procedure X509_TRUST_get0()
  86.   }
  87.   
  88. > X509_TRUST *X509_TRUST_get0(int idx)
  89.   {
  90.       if (idx < 0)

crypto/x509/x509_trs.c:90:9: Taking true branch
  88.   X509_TRUST *X509_TRUST_get0(int idx)
  89.   {
  90.       if (idx < 0)
                ^
  91.           return NULL;
  92.       if (idx < (int)X509_TRUST_COUNT)

crypto/x509/x509_trs.c:91:9: 
  89.   {
  90.       if (idx < 0)
  91. >         return NULL;
  92.       if (idx < (int)X509_TRUST_COUNT)
  93.           return trstandard + idx;

crypto/x509/x509_trs.c:95:1: return from a call to X509_TRUST_get0
  93.           return trstandard + idx;
  94.       return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
  95. > }
  96.   
  97.   int X509_TRUST_get_by_id(int id)

crypto/x509/x509_trs.c:146:9: 
144.   
145.       /* OPENSSL_free existing name if dynamic */
146. >     if (trtmp->flags & X509_TRUST_DYNAMIC_NAME)
147.           OPENSSL_free(trtmp->name);
148.       /* dup supplied name */

int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int),
                   const char *name, int arg1, void *arg2)
{
    int idx;
    X509_TRUST *trtmp;
    flags &= ~X509_TRUST_DYNAMIC;
    flags |= X509_TRUST_DYNAMIC_NAME;
    idx = X509_TRUST_get_by_id(id);
    if (idx == -1) {
        if ((trtmp = OPENSSL_malloc(sizeof(*trtmp))) == NULL) {
            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
            return 0;
        }
        trtmp->flags = X509_TRUST_DYNAMIC;
    } else
        trtmp = X509_TRUST_get0(idx);
    if (trtmp->flags & X509_TRUST_DYNAMIC_NAME)
        OPENSSL_free(trtmp->name);
    if ((trtmp->name = OPENSSL_strdup(name)) == NULL) {
        X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    trtmp->flags &= X509_TRUST_DYNAMIC;
    trtmp->flags |= flags;
    trtmp->trust = id;
    trtmp->check_trust = ck;
    trtmp->arg1 = arg1;
    trtmp->arg2 = arg2;
    if (idx == -1) {
        if (trtable == NULL
            && (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL) {
            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
            goto err;;
        }
        if (!sk_X509_TRUST_push(trtable, trtmp)) {
            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
            goto err;
        }
    }
    return 1;
 err:
    if (idx == -1) {
        OPENSSL_free(trtmp->name);
        OPENSSL_free(trtmp);
    }
    return 0;
}
['int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int),\n                   const char *name, int arg1, void *arg2)\n{\n    int idx;\n    X509_TRUST *trtmp;\n    flags &= ~X509_TRUST_DYNAMIC;\n    flags |= X509_TRUST_DYNAMIC_NAME;\n    idx = X509_TRUST_get_by_id(id);\n    if (idx == -1) {\n        if ((trtmp = OPENSSL_malloc(sizeof(*trtmp))) == NULL) {\n            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);\n            return 0;\n        }\n        trtmp->flags = X509_TRUST_DYNAMIC;\n    } else\n        trtmp = X509_TRUST_get0(idx);\n    if (trtmp->flags & X509_TRUST_DYNAMIC_NAME)\n        OPENSSL_free(trtmp->name);\n    if ((trtmp->name = OPENSSL_strdup(name)) == NULL) {\n        X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    trtmp->flags &= X509_TRUST_DYNAMIC;\n    trtmp->flags |= flags;\n    trtmp->trust = id;\n    trtmp->check_trust = ck;\n    trtmp->arg1 = arg1;\n    trtmp->arg2 = arg2;\n    if (idx == -1) {\n        if (trtable == NULL\n            && (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL) {\n            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);\n            goto err;;\n        }\n        if (!sk_X509_TRUST_push(trtable, trtmp)) {\n            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n    }\n    return 1;\n err:\n    if (idx == -1) {\n        OPENSSL_free(trtmp->name);\n        OPENSSL_free(trtmp);\n    }\n    return 0;\n}', 'int X509_TRUST_get_by_id(int id)\n{\n    X509_TRUST tmp;\n    int idx;\n    if ((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))\n        return id - X509_TRUST_MIN;\n    tmp.trust = id;\n    if (!trtable)\n        return -1;\n    idx = sk_X509_TRUST_find(trtable, &tmp);\n    if (idx == -1)\n        return -1;\n    return idx + X509_TRUST_COUNT;\n}', 'int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)\n{\n    return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(OPENSSL_STACK *st, const void *data,\n                         int ret_val_options)\n{\n    const void *r;\n    int i;\n    if (st == NULL)\n        return -1;\n    if (st->comp == NULL) {\n        for (i = 0; i < st->num; i++)\n            if (st->data[i] == data)\n                return (i);\n        return (-1);\n    }\n    OPENSSL_sk_sort(st);\n    if (data == NULL)\n        return (-1);\n    r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp,\n                        ret_val_options);\n    if (r == NULL)\n        return (-1);\n    return (int)((const char **)r - st->data);\n}', 'X509_TRUST *X509_TRUST_get0(int idx)\n{\n    if (idx < 0)\n        return NULL;\n    if (idx < (int)X509_TRUST_COUNT)\n        return trstandard + idx;\n    return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);\n}']