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


crypto/x509/x_name.c:268:1: start of procedure x509_name_encode()
266.   }
267.   
268. > static int x509_name_encode(X509_NAME *a)
269.   {
270.       union {

crypto/x509/x_name.c:270:5: 
268.   static int x509_name_encode(X509_NAME *a)
269.   {
270. >     union {
271.           STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
272.           ASN1_VALUE *a;

crypto/x509/x_name.c:278:5: 
276.       int len;
277.       unsigned char *p;
278. >     STACK_OF(X509_NAME_ENTRY) *entries = NULL;
279.       X509_NAME_ENTRY *entry;
280.       int i, set = -1;

crypto/x509/x_name.c:280:5: 
278.       STACK_OF(X509_NAME_ENTRY) *entries = NULL;
279.       X509_NAME_ENTRY *entry;
280. >     int i, set = -1;
281.       intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
282.       if (!intname.s)

crypto/x509/x_name.c:281:5: 
279.       X509_NAME_ENTRY *entry;
280.       int i, set = -1;
281. >     intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
282.       if (!intname.s)
283.           goto memerr;

crypto/stack/stack.c:145:1: start of procedure sk_new_null()
  143.   }
  144.   
  145. > _STACK *sk_new_null(void)
  146.   {
  147.       return sk_new((int (*)(const void *, const void *))0);

crypto/stack/stack.c:147:5: Skipping sk_new(): empty list of specs
  145.   _STACK *sk_new_null(void)
  146.   {
  147.       return sk_new((int (*)(const void *, const void *))0);
             ^
  148.   }
  149.   

crypto/stack/stack.c:148:1: return from a call to sk_new_null
  146.   {
  147.       return sk_new((int (*)(const void *, const void *))0);
  148. > }
  149.   
  150.   _STACK *sk_new(int (*c) (const void *, const void *))

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

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

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

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

crypto/stack/stack.c:317:1: start of procedure sk_num()
  315.   }
  316.   
  317. > int sk_num(const _STACK *st)
  318.   {
  319.       if (st == NULL)

crypto/stack/stack.c:319:9: Taking false branch
  317.   int sk_num(const _STACK *st)
  318.   {
  319.       if (st == NULL)
                 ^
  320.           return -1;
  321.       return st->num;

crypto/stack/stack.c:321:5: 
  319.       if (st == NULL)
  320.           return -1;
  321. >     return st->num;
  322.   }
  323.   

crypto/stack/stack.c:322:1: return from a call to sk_num
  320.           return -1;
  321.       return st->num;
  322. > }
  323.   
  324.   void *sk_value(const _STACK *st, int i)

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

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

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

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 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:328:5: 
  326.       if (!st || (i < 0) || (i >= st->num))
  327.           return NULL;
  328. >     return st->data[i];
  329.   }
  330.   

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/x_name.c:286:13: Taking false branch
284.       for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
285.           entry = sk_X509_NAME_ENTRY_value(a->entries, i);
286.           if (entry->set != set) {
                   ^
287.               entries = sk_X509_NAME_ENTRY_new_null();
288.               if (!entries)

crypto/x509/x_name.c:294:14: Condition is true
292.               set = entry->set;
293.           }
294.           if (!sk_X509_NAME_ENTRY_push(entries, entry))
                    ^
295.               goto memerr;
296.       }

crypto/x509/x_name.c:294:14: Condition is true
292.               set = entry->set;
293.           }
294.           if (!sk_X509_NAME_ENTRY_push(entries, entry))
                    ^
295.               goto memerr;
296.       }

crypto/stack/stack.c:259:1: start of procedure sk_push()
  257.   }
  258.   
  259. > int sk_push(_STACK *st, void *data)
  260.   {
  261.       return (sk_insert(st, data, st->num));

crypto/stack/stack.c:261:5: Skipping sk_insert(): empty list of specs
  259.   int sk_push(_STACK *st, void *data)
  260.   {
  261.       return (sk_insert(st, data, st->num));
             ^
  262.   }
  263.   

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}']