Author: abartlet Date: 2004-09-06 02:56:49 +0000 (Mon, 06 Sep 2004) New Revision: 48
WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=lorikeet&path=/trunk/heimdal/lib/hdb&rev=48&nolog=1 Log: Fix valgrind errors by simply allocating the enctypes[] array. Andrew Bartlett Modified: trunk/heimdal/lib/hdb/keys.c Changeset: Modified: trunk/heimdal/lib/hdb/keys.c =================================================================== --- trunk/heimdal/lib/hdb/keys.c 2004-09-06 02:55:59 UTC (rev 47) +++ trunk/heimdal/lib/hdb/keys.c 2004-09-06 02:56:49 UTC (rev 48) @@ -78,7 +78,6 @@ char buf[3][256]; int num_buf = 0; int i; - static krb5_enctype e; /* XXX */ krb5_error_code ret; /* the 3 DES types must be first */ @@ -112,18 +111,21 @@ /* XXX there should be a string_to_etypes handling special cases like `des' and `all' */ if(strcmp(buf[i], "des") == 0) { - *enctypes = all_etypes; + *enctypes = malloc(sizeof(all_etypes[0])*3); + memcpy(*enctypes, all_etypes, sizeof(all_etypes[0])*3); *num_enctypes = 3; continue; } else if(strcmp(buf[i], "des3") == 0) { - e = ETYPE_DES3_CBC_SHA1; - *enctypes = &e; + *enctypes = malloc(sizeof(**enctypes)); + *enctypes[0] = ETYPE_DES3_CBC_SHA1; *num_enctypes = 1; continue; } else { + krb5_enctype e; ret = krb5_string_to_enctype(context, buf[i], &e); if (ret == 0) { - *enctypes = &e; + *enctypes = malloc(sizeof(**enctypes)); + *enctypes[0] = e; *num_enctypes = 1; continue; } @@ -137,13 +139,15 @@ interface sucks */ if(strcmp(buf[i], "pw-salt") == 0) { if(*enctypes == NULL) { - *enctypes = all_etypes; + *enctypes = malloc(sizeof(all_etypes)); + memcpy(*enctypes, all_etypes, sizeof(all_etypes)); *num_enctypes = sizeof(all_etypes)/sizeof(all_etypes[0]); } salt->salttype = KRB5_PW_SALT; } else if(strcmp(buf[i], "afs3-salt") == 0) { if(*enctypes == NULL) { - *enctypes = all_etypes; + *enctypes = malloc(sizeof(all_etypes[0])*3); + memcpy(*enctypes, all_etypes, sizeof(all_etypes[0])*3); *num_enctypes = 3; } salt->salttype = KRB5_AFS3_SALT; @@ -172,6 +176,7 @@ if(salt->saltvalue.data == NULL) { krb5_set_error_string(context, "out of memory while " "parsing salt specifiers"); + free(*enctypes); return ENOMEM; } strlwr(salt->saltvalue.data); @@ -313,10 +318,13 @@ if (j == *nkeyset) { ret = add_enctype_to_key_set(&key_set, nkeyset, enctypes[i], no_salt ? NULL : &salt); - if (ret) - goto out; + if (ret) { + free(enctypes); + goto out; + } } } + free(enctypes); } out: