From: John Kohl Date: Fri, 19 Apr 1991 14:34:20 +0000 (+0000) Subject: clean up some stuff; remove length restriction X-Git-Tag: krb5-1.0-alpha5~95 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=55a26d6ddb70b5adaf8f75e37408f00530f6511a;p=krb5.git clean up some stuff; remove length restriction git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2006 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/des/string2key.c b/src/lib/crypto/des/string2key.c index 7453ddeac..1b5392246 100644 --- a/src/lib/crypto/des/string2key.c +++ b/src/lib/crypto/des/string2key.c @@ -51,9 +51,7 @@ OLDDECLARG(krb5_keyblock *,keyblock) OLDDECLARG(const krb5_data *,data) OLDDECLARG(const krb5_data *, salt) { - char copystr[512]; - - register char *str = copystr; + register char *str, *copystr; register krb5_octet *key; register unsigned temp,i; @@ -73,25 +71,26 @@ OLDDECLARG(const krb5_data *, salt) if ( !(keyblock->contents = (krb5_octet *)malloc(sizeof(mit_des_cblock))) ) return(ENOMEM); -#define cleanup() {memset(keyblock->contents, 0, sizeof(mit_des_cblock));\ - xfree(keyblock->contents);} - keyblock->keytype = KEYTYPE_DES; keyblock->length = sizeof(mit_des_cblock); key = keyblock->contents; - /* XXX todo: make it work in face of embedded NUL's */ - memset(copystr, 0, sizeof(copystr)); - j = min(data->length, 511); - (void) strncpy(copystr, data->data, j); - if (salt) { - strncpy (copystr + j, salt->data, min(salt->length, 511-j)); - } + if (salt) + length = data->length + salt->length; + else + length = data->length; + + copystr = malloc(length); + if (!copystr) + return ENOMEM; - /* convert copystr to des key */ + memcpy(copystr, (char *) data->data, data->length); + if (salt) + memcpy(copystr + data->length, (char *)salt->data, salt->length); + + /* convert to des key */ forward = 1; p_char = k_char; - length = strlen(str); /* init key array for bits */ memset(k_char,0,sizeof(k_char)); @@ -99,10 +98,12 @@ OLDDECLARG(const krb5_data *, salt) #ifdef DEBUG if (mit_des_debug) fprintf(stdout, - "\n\ninput str length = %d string = %s\nstring = 0x ", - length,str); + "\n\ninput str length = %d string = %*s\nstring = 0x ", + length,length,str); #endif + str = copystr; + /* get next 8 bytes, strip parity, xor */ for (i = 1; i <= length; i++) { /* get next input key byte */ @@ -145,6 +146,10 @@ OLDDECLARG(const krb5_data *, salt) /* erase key_sked */ memset((char *)key_sked, 0, sizeof(key_sked)); + /* clean & free the input string */ + memset(copystr, 0, length); + xfree(copystr); + /* now fix up key parity again */ mit_des_fixup_key_parity(key);