crypto/asn1/x_name.c:297: error: NULL_DEREFERENCE
  pointer `entries` last assigned on line 281 could be null and is dereferenced by call to `sk_push()` at line 297, column 14.
Showing all 30 steps of the trace


crypto/asn1/x_name.c:271:1: start of procedure x509_name_encode()
269.   }
270.   
271. > static int x509_name_encode(X509_NAME *a)
272.   {
273.       union {

crypto/asn1/x_name.c:273:5: 
271.   static int x509_name_encode(X509_NAME *a)
272.   {
273. >     union {
274.           STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
275.           ASN1_VALUE *a;

crypto/asn1/x_name.c:281:5: 
279.       int len;
280.       unsigned char *p;
281. >     STACK_OF(X509_NAME_ENTRY) *entries = NULL;
282.       X509_NAME_ENTRY *entry;
283.       int i, set = -1;

crypto/asn1/x_name.c:283:5: 
281.       STACK_OF(X509_NAME_ENTRY) *entries = NULL;
282.       X509_NAME_ENTRY *entry;
283. >     int i, set = -1;
284.       intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
285.       if (!intname.s)

crypto/asn1/x_name.c:284:5: 
282.       X509_NAME_ENTRY *entry;
283.       int i, set = -1;
284. >     intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
285.       if (!intname.s)
286.           goto memerr;

crypto/stack/stack.c:152:1: start of procedure sk_new_null()
  150.   }
  151.   
  152. > _STACK *sk_new_null(void)
  153.   {
  154.       return sk_new((int (*)(const void *, const void *))0);

crypto/stack/stack.c:154:5: Skipping sk_new(): empty list of specs
  152.   _STACK *sk_new_null(void)
  153.   {
  154.       return sk_new((int (*)(const void *, const void *))0);
             ^
  155.   }
  156.   

crypto/stack/stack.c:155:1: return from a call to sk_new_null
  153.   {
  154.       return sk_new((int (*)(const void *, const void *))0);
  155. > }
  156.   
  157.   _STACK *sk_new(int (*c) (const void *, const void *))

crypto/asn1/x_name.c:285:10: Taking false branch
283.       int i, set = -1;
284.       intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
285.       if (!intname.s)
                ^
286.           goto memerr;
287.       for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {

crypto/asn1/x_name.c:287:10: 
285.       if (!intname.s)
286.           goto memerr;
287. >     for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
288.           entry = sk_X509_NAME_ENTRY_value(a->entries, i);
289.           if (entry->set != set) {

crypto/asn1/x_name.c:287:21: Condition is true
285.       if (!intname.s)
286.           goto memerr;
287.       for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
                           ^
288.           entry = sk_X509_NAME_ENTRY_value(a->entries, i);
289.           if (entry->set != set) {

crypto/asn1/x_name.c:287:17: 
285.       if (!intname.s)
286.           goto memerr;
287. >     for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
288.           entry = sk_X509_NAME_ENTRY_value(a->entries, i);
289.           if (entry->set != set) {

crypto/stack/stack.c:340:1: start of procedure sk_num()
  338.   }
  339.   
  340. > int sk_num(const _STACK *st)
  341.   {
  342.       if (st == NULL)

crypto/stack/stack.c:342:9: Taking false branch
  340.   int sk_num(const _STACK *st)
  341.   {
  342.       if (st == NULL)
                 ^
  343.           return -1;
  344.       return st->num;

crypto/stack/stack.c:344:5: 
  342.       if (st == NULL)
  343.           return -1;
  344. >     return st->num;
  345.   }
  346.   

crypto/stack/stack.c:345:1: return from a call to sk_num
  343.           return -1;
  344.       return st->num;
  345. > }
  346.   
  347.   void *sk_value(const _STACK *st, int i)

crypto/asn1/x_name.c:287:17: Loop condition is true. Entering loop body
285.       if (!intname.s)
286.           goto memerr;
287.       for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
                       ^
288.           entry = sk_X509_NAME_ENTRY_value(a->entries, i);
289.           if (entry->set != set) {

crypto/asn1/x_name.c:288:17: Condition is true
286.           goto memerr;
287.       for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
288.           entry = sk_X509_NAME_ENTRY_value(a->entries, i);
                       ^
289.           if (entry->set != set) {
290.               entries = sk_X509_NAME_ENTRY_new_null();

crypto/asn1/x_name.c:288:9: 
286.           goto memerr;
287.       for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
288. >         entry = sk_X509_NAME_ENTRY_value(a->entries, i);
289.           if (entry->set != set) {
290.               entries = sk_X509_NAME_ENTRY_new_null();

crypto/stack/stack.c:347:1: start of procedure sk_value()
  345.   }
  346.   
  347. > void *sk_value(const _STACK *st, int i)
  348.   {
  349.       if (!st || (i < 0) || (i >= st->num))

crypto/stack/stack.c:349:10: Taking false branch
  347.   void *sk_value(const _STACK *st, int i)
  348.   {
  349.       if (!st || (i < 0) || (i >= st->num))
                  ^
  350.           return NULL;
  351.       return st->data[i];

crypto/stack/stack.c:349:17: Taking false branch
  347.   void *sk_value(const _STACK *st, int i)
  348.   {
  349.       if (!st || (i < 0) || (i >= st->num))
                         ^
  350.           return NULL;
  351.       return st->data[i];

crypto/stack/stack.c:349:28: Taking false branch
  347.   void *sk_value(const _STACK *st, int i)
  348.   {
  349.       if (!st || (i < 0) || (i >= st->num))
                                    ^
  350.           return NULL;
  351.       return st->data[i];

crypto/stack/stack.c:351:5: 
  349.       if (!st || (i < 0) || (i >= st->num))
  350.           return NULL;
  351. >     return st->data[i];
  352.   }
  353.   

crypto/stack/stack.c:352:1: return from a call to sk_value
  350.           return NULL;
  351.       return st->data[i];
  352. > }
  353.   
  354.   void *sk_set(_STACK *st, int i, void *value)

crypto/asn1/x_name.c:289:13: Taking false branch
287.       for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
288.           entry = sk_X509_NAME_ENTRY_value(a->entries, i);
289.           if (entry->set != set) {
                   ^
290.               entries = sk_X509_NAME_ENTRY_new_null();
291.               if (!entries)

crypto/asn1/x_name.c:297:14: Condition is true
295.               set = entry->set;
296.           }
297.           if (!sk_X509_NAME_ENTRY_push(entries, entry))
                    ^
298.               goto memerr;
299.       }

crypto/asn1/x_name.c:297:14: Condition is true
295.               set = entry->set;
296.           }
297.           if (!sk_X509_NAME_ENTRY_push(entries, entry))
                    ^
298.               goto memerr;
299.       }

crypto/stack/stack.c:281:1: start of procedure sk_push()
  279.   }
  280.   
  281. > int sk_push(_STACK *st, void *data)
  282.   {
  283.       return (sk_insert(st, data, st->num));

crypto/stack/stack.c:283:5: Skipping sk_insert(): empty list of specs
  281.   int sk_push(_STACK *st, void *data)
  282.   {
  283.       return (sk_insert(st, data, st->num));
             ^
  284.   }
  285.   

static int x509_name_encode(X509_NAME *a)
{
    union {
        STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
        ASN1_VALUE *a;
    } intname = {
        NULL
    };
    int len;
    unsigned char *p;
    STACK_OF(X509_NAME_ENTRY) *entries = NULL;
    X509_NAME_ENTRY *entry;
    int i, set = -1;
    intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
    if (!intname.s)
        goto memerr;
    for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
        entry = sk_X509_NAME_ENTRY_value(a->entries, i);
        if (entry->set != set) {
            entries = sk_X509_NAME_ENTRY_new_null();
            if (!entries)
                goto memerr;
            if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s, entries))
                goto memerr;
            set = entry->set;
        }
        if (!sk_X509_NAME_ENTRY_push(entries, entry))
            goto memerr;
    }
    len = ASN1_item_ex_i2d(&intname.a, NULL,
                           ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
    if (!BUF_MEM_grow(a->bytes, len))
        goto memerr;
    p = (unsigned char *)a->bytes->data;
    ASN1_item_ex_i2d(&intname.a,
                     &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
    sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
                                         local_sk_X509_NAME_ENTRY_free);
    a->modified = 0;
    return len;
 memerr:
    sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
                                         local_sk_X509_NAME_ENTRY_free);
    ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE);
    return -1;
}
['static int x509_name_encode(X509_NAME *a)\n{\n    union {\n        STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;\n        ASN1_VALUE *a;\n    } intname = {\n        NULL\n    };\n    int len;\n    unsigned char *p;\n    STACK_OF(X509_NAME_ENTRY) *entries = NULL;\n    X509_NAME_ENTRY *entry;\n    int i, set = -1;\n    intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();\n    if (!intname.s)\n        goto memerr;\n    for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {\n        entry = sk_X509_NAME_ENTRY_value(a->entries, i);\n        if (entry->set != set) {\n            entries = sk_X509_NAME_ENTRY_new_null();\n            if (!entries)\n                goto memerr;\n            if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s, entries))\n                goto memerr;\n            set = entry->set;\n        }\n        if (!sk_X509_NAME_ENTRY_push(entries, entry))\n            goto memerr;\n    }\n    len = ASN1_item_ex_i2d(&intname.a, NULL,\n                           ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);\n    if (!BUF_MEM_grow(a->bytes, len))\n        goto memerr;\n    p = (unsigned char *)a->bytes->data;\n    ASN1_item_ex_i2d(&intname.a,\n                     &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);\n    sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,\n                                         local_sk_X509_NAME_ENTRY_free);\n    a->modified = 0;\n    return len;\n memerr:\n    sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,\n                                         local_sk_X509_NAME_ENTRY_free);\n    ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE);\n    return -1;\n}', '_STACK *sk_new_null(void)\n{\n    return sk_new((int (*)(const void *, const void *))0);\n}', 'int sk_num(const _STACK *st)\n{\n    if (st == NULL)\n        return -1;\n    return st->num;\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}', 'int sk_push(_STACK *st, void *data)\n{\n    return (sk_insert(st, data, st->num));\n}']