From 7905cd6a2eddbf264242bb2a85f811878b2da7ab Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Sat, 9 Feb 2013 00:43:35 -0500 Subject: Add and use k5memdup, k5memdup0 helpers Add k5-int.h static functions to duplicate byte ranges, optionally with a trailing zero byte, and set an error code like k5alloc does. Use them where they would shorten existing code. --- src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c | 18 ++++++------------ src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c | 7 ++----- 2 files changed, 8 insertions(+), 17 deletions(-) (limited to 'src/plugins/kdb/ldap') diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c index 5f789da98..c4024b8d0 100644 --- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c +++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c @@ -826,11 +826,9 @@ decode_tl_data(krb5_tl_data *tl_data, int tl_type, void **data) UNSTORE16_INT(curr, sublen); /* forward by 2 bytes */ curr += 2; - DN = malloc (sublen + 1); + DN = k5memdup0(curr, sublen, &st); if (DN == NULL) - return ENOMEM; - memcpy(DN, curr, sublen); - DN[sublen] = 0; + return st; *data = DN; curr += sublen; st = 0; @@ -854,11 +852,9 @@ decode_tl_data(krb5_tl_data *tl_data, int tl_type, void **data) UNSTORE16_INT(curr, sublen); /* forward by 2 bytes */ curr += 2; - DNarr[i] = malloc (sublen + 1); + DNarr[i] = k5memdup0(curr, sublen, &st); if (DNarr[i] == NULL) - return ENOMEM; - memcpy(DNarr[i], curr, sublen); - DNarr[i][sublen] = 0; + return st; ++i; curr += sublen; *data = DNarr; @@ -1292,12 +1288,10 @@ krb5_add_ber_mem_ldap_mod(LDAPMod ***mods, char *attribute, int op, return ENOMEM; (*mods)[i]->mod_bvalues[j]->bv_len = ber_values[j]->bv_len; - (*mods)[i]->mod_bvalues[j]->bv_val = malloc((*mods)[i]->mod_bvalues[j]->bv_len); + (*mods)[i]->mod_bvalues[j]->bv_val = + k5memdup(ber_values[j]->bv_val, ber_values[j]->bv_len, &st); if ((*mods)[i]->mod_bvalues[j]->bv_val == NULL) return ENOMEM; - - memcpy((*mods)[i]->mod_bvalues[j]->bv_val, ber_values[j]->bv_val, - ber_values[j]->bv_len); } (*mods)[i]->mod_bvalues[j] = NULL; return 0; diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c index 1e671c7ed..527873c1f 100644 --- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c +++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c @@ -331,12 +331,9 @@ process_db_args(krb5_context context, char **db_args, xargs_t *xargs, dptr)) != 0) goto cleanup; } else { - *dptr = calloc (1, arg_val_len); - if (*dptr == NULL) { - st = ENOMEM; + *dptr = k5memdup(arg_val, arg_val_len, &st); + if (*dptr == NULL) goto cleanup; - } - memcpy(*dptr, arg_val, arg_val_len); } } } -- cgit