From 3256e507e0b4ab39658e3d0fb89ab85cf6301142 Mon Sep 17 00:00:00 2001 From: John Kohl Date: Thu, 27 Sep 1990 17:03:29 +0000 Subject: [PATCH] rework it to not require a fixed size encode buffer git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1148 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/asn.1/encode.c | 45 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/lib/krb5/asn.1/encode.c b/src/lib/krb5/asn.1/encode.c index 7cb8ee091..33340dfc1 100644 --- a/src/lib/krb5/asn.1/encode.c +++ b/src/lib/krb5/asn.1/encode.c @@ -37,22 +37,10 @@ void (*free_translation) PROTOTYPE((krb5_pointer )); krb5_pointer isode_out; PE pe; PS ps; - char encode_buf[BUFSIZ]; krb5_error_code error; if (!(isode_out = (*translator)(input, &error))) return(error); - if (!(ps = ps_alloc(str_open))) { - free_translation(isode_out); - return(ENOMEM); - } - if (str_setup(ps, encode_buf, sizeof(encode_buf), 1) != OK) { - error = ps->ps_errno + ISODE_50_PS_ERR_NONE; - errout: - ps_free(ps); - free_translation(isode_out); - return(error); - } if ((*encoder)(&pe, 0, 0, 0, isode_out)) { error = ENOMEM; goto errout; @@ -60,28 +48,39 @@ void (*free_translation) PROTOTYPE((krb5_pointer )); *data_out = (krb5_data *)malloc(sizeof(**data_out)); if (!*data_out) { error = ENOMEM; - goto errout; + goto peout; } - if (((*data_out)->length = ps_get_abs(pe)) > sizeof(encode_buf)) { - abort(); /* xxx */ - } - (*data_out)->data = malloc(ps_get_abs(pe)); + (*data_out)->length = ps_get_abs(pe); + (*data_out)->data = malloc((*data_out)->length); if (!(*data_out)->data) { error = ENOMEM; - free((char *)*data_out); - *data_out = 0; - goto errout; + goto datout; + } + if (!(ps = ps_alloc(str_open))) { + error = ENOMEM; + goto alldatout; + } + if (str_setup(ps, (*data_out)->data, (*data_out)->length, 1) != OK) { + error = ps->ps_errno + ISODE_50_PS_ERR_NONE; + goto oops; } if (pe2ps(ps, pe) != OK || ps_flush(ps) != OK) { error = ps->ps_errno + ISODE_50_PS_ERR_NONE; + oops: + ps_free(ps); + alldatout: free((*data_out)->data); + datout: free((char *)*data_out); *data_out = 0; - goto errout; + peout: + pe_free(pe); + errout: + (*free_translation)(isode_out); + return(error); } - bcopy(encode_buf, (*data_out)->data, (*data_out)->length); ps_free(ps); pe_free(pe); - free_translation(isode_out); + (*free_translation)(isode_out); return(0); } -- 2.26.2