Added fix to avoid the malloc(0) problem
authorTheodore Tso <tytso@mit.edu>
Tue, 23 Feb 1993 14:19:33 +0000 (14:19 +0000)
committerTheodore Tso <tytso@mit.edu>
Tue, 23 Feb 1993 14:19:33 +0000 (14:19 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2500 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/asn.1/kdcr2kkdcr.c
src/lib/krb5/asn.1/tgrq2ktgrq.c

index 0e3cf5f4d4181136477fe06d4de97bd1d1925bb6..412e5a69d85435a164df2b01be059d8ba2b09618 100644 (file)
@@ -72,18 +72,21 @@ element_KRB5_112krb5_pa_data(val, error)
            *error = ENOMEM;
            return(0);
        }
-       retval[i]->contents = (unsigned char *)xmalloc(rv->PA__DATA->pa__data->qb_forw->qb_len);
-       if (!retval[i]->contents) {
-           xfree(retval[i]);
-           retval[i] = 0;
-           krb5_free_pa_data(retval);
-           *error = ENOMEM;
-           return(0);
-       }
        retval[i]->pa_type = rv->PA__DATA->padata__type;
        retval[i]->length = rv->PA__DATA->pa__data->qb_forw->qb_len;
-       xbcopy(rv->PA__DATA->pa__data->qb_forw->qb_data,
-             retval[i]->contents, retval[i]->length);
+       if (retval[i]->length) {
+           retval[i]->contents = (unsigned char *)xmalloc(rv->PA__DATA->pa__data->qb_forw->qb_len);
+           if (!retval[i]->contents) {
+               xfree(retval[i]);
+               retval[i] = 0;
+               krb5_free_pa_data(retval);
+               *error = ENOMEM;
+               return(0);
+           }
+           xbcopy(rv->PA__DATA->pa__data->qb_forw->qb_data,
+                  retval[i]->contents, retval[i]->length);
+        } else
+           retval[i]->contents = 0;
     }
     retval[i] = 0;
     return(retval);
index 8a08d880c01810d90e282d0d2326214de213c420..ea14beeb90178689c36fa12b4167c299d7919807 100644 (file)
@@ -232,18 +232,20 @@ element_KRB5_72krb5_pa_data(val, error)
            *error = ENOMEM;
            return(0);
        }
-       retval[i]->contents = (unsigned char *)xmalloc(rv->PA__DATA->pa__data->qb_forw->qb_len);
-       if (!retval[i]->contents) {
-           xfree(retval[i]);
-           retval[i] = 0;
-           krb5_free_pa_data(retval);
-           *error = ENOMEM;
-           return(0);
-       }
        retval[i]->pa_type = rv->PA__DATA->padata__type;
        retval[i]->length = rv->PA__DATA->pa__data->qb_forw->qb_len;
-       xbcopy(rv->PA__DATA->pa__data->qb_forw->qb_data,
-             retval[i]->contents, retval[i]->length);
+       if (retval[i]->length) {
+           retval[i]->contents = (unsigned char *)xmalloc(rv->PA__DATA->pa__data->qb_forw->qb_len);
+           if (!retval[i]->contents) {
+               xfree(retval[i]);
+               retval[i] = 0;
+               krb5_free_pa_data(retval);
+               *error = ENOMEM;
+               return(0);
+           }
+           xbcopy(rv->PA__DATA->pa__data->qb_forw->qb_data,
+                  retval[i]->contents, retval[i]->length);
+       }
     }
     retval[i] = 0;
     return(retval);