svn rev #21981: trunk/src/lib/krb5/asn.1/
ghudson@MIT.EDU
ghudson at MIT.EDU
Thu Feb 12 13:21:33 EST 2009
http://src.mit.edu/fisheye/changelog/krb5/?cs=21981
Commit By: ghudson
Log Message:
Modify asn12krb5_buf and asn1_do_full_encode to make output parameter
values well-defined on error. Clean up memory handling and an unused
variable in asn1_do_full_encode.
Changed Files:
U trunk/src/lib/krb5/asn.1/asn1_encode.c
U trunk/src/lib/krb5/asn.1/asn1buf.c
Modified: trunk/src/lib/krb5/asn.1/asn1_encode.c
===================================================================
--- trunk/src/lib/krb5/asn.1/asn1_encode.c 2009-02-12 17:51:45 UTC (rev 21980)
+++ trunk/src/lib/krb5/asn.1/asn1_encode.c 2009-02-12 18:21:33 UTC (rev 21981)
@@ -675,20 +675,26 @@
{
unsigned int length;
asn1_error_code retval;
- unsigned int sum = 0;
asn1buf *buf = NULL;
+ krb5_data *d;
- if (rep == NULL) return ASN1_MISSING_FIELD;
+ *code = NULL;
+ if (rep == NULL)
+ return ASN1_MISSING_FIELD;
+
retval = asn1buf_create(&buf);
if (retval)
return retval;
retval = krb5int_asn1_encode_a_thing(buf, rep, a, &length);
if (retval)
- return retval;
- sum += length;
- retval = asn12krb5_buf(buf, code);
+ goto cleanup;
+ retval = asn12krb5_buf(buf, &d);
+ if (retval)
+ goto cleanup;
+ *code = d;
+cleanup:
asn1buf_destroy(&buf);
return retval;
}
Modified: trunk/src/lib/krb5/asn.1/asn1buf.c
===================================================================
--- trunk/src/lib/krb5/asn.1/asn1buf.c 2009-02-12 17:51:45 UTC (rev 21980)
+++ trunk/src/lib/krb5/asn.1/asn1buf.c 2009-02-12 18:21:33 UTC (rev 21981)
@@ -253,21 +253,24 @@
asn1_error_code asn12krb5_buf(const asn1buf *buf, krb5_data **code)
{
unsigned int i;
- *code = (krb5_data*)calloc(1,sizeof(krb5_data));
- if (*code == NULL) return ENOMEM;
- (*code)->magic = KV5M_DATA;
- (*code)->data = NULL;
- (*code)->length = 0;
- (*code)->length = asn1buf_len(buf);
- (*code)->data = (char*)malloc((((*code)->length)+1)*sizeof(char));
- if ((*code)->data == NULL) {
- free(*code);
- *code = NULL;
+ krb5_data *d;
+
+ *code = NULL;
+
+ d = calloc(1, sizeof(krb5_data));
+ if (d == NULL)
return ENOMEM;
+ d->length = asn1buf_len(buf);
+ d->data = malloc(d->length + 1);
+ if (d->data == NULL) {
+ free(d);
+ return ENOMEM;
}
- for (i=0; i < (*code)->length; i++)
- ((*code)->data)[i] = (buf->base)[((*code)->length)-i-1];
- ((*code)->data)[(*code)->length] = '\0';
+ for (i=0; i < d->length; i++)
+ d->data[i] = buf->base[d->length - i - 1];
+ d->data[d->length] = '\0';
+ d->magic = KV5M_DATA;
+ *code = d;
return 0;
}
More information about the cvs-krb5
mailing list