diff options
author | Jeremy Allison <jra@samba.org> | 2004-12-07 18:25:53 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:53:32 -0500 |
commit | acf9d61421faa6c0055d57fdee7db300dc5431aa (patch) | |
tree | 5482afecfe9b4a68b9a1f18d541a3109f8143ab7 /source3/libads | |
parent | 3bd3be97dc8a581c0502410453091c195e322766 (diff) | |
download | samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.gz samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.bz2 samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.zip |
r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
functions so we can funnel through some well known functions. Should help greatly with
malloc checking.
HEAD patch to follow.
Jeremy.
(This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a)
Diffstat (limited to 'source3/libads')
-rw-r--r-- | source3/libads/ads_struct.c | 12 | ||||
-rw-r--r-- | source3/libads/authdata.c | 34 | ||||
-rw-r--r-- | source3/libads/kerberos_keytab.c | 2 | ||||
-rw-r--r-- | source3/libads/kerberos_verify.c | 2 | ||||
-rw-r--r-- | source3/libads/krb5_setpw.c | 8 | ||||
-rw-r--r-- | source3/libads/ldap.c | 60 | ||||
-rw-r--r-- | source3/libads/ldap_printer.c | 5 | ||||
-rw-r--r-- | source3/libads/ldap_utils.c | 2 | ||||
-rw-r--r-- | source3/libads/sasl.c | 2 |
9 files changed, 58 insertions, 69 deletions
diff --git a/source3/libads/ads_struct.c b/source3/libads/ads_struct.c index 92f37093f4..e8546f86f5 100644 --- a/source3/libads/ads_struct.c +++ b/source3/libads/ads_struct.c @@ -31,7 +31,7 @@ char *ads_build_path(const char *realm, const char *sep, const char *field, int char *ret; int len; - r = strdup(realm); + r = SMB_STRDUP(realm); if (!r || !*r) return r; @@ -42,7 +42,7 @@ char *ads_build_path(const char *realm, const char *sep, const char *field, int len = (numbits+1)*(strlen(field)+1) + strlen(r) + 1; - ret = malloc(len); + ret = SMB_MALLOC(len); if (!ret) return NULL; @@ -87,12 +87,12 @@ ADS_STRUCT *ads_init(const char *realm, { ADS_STRUCT *ads; - ads = (ADS_STRUCT *)smb_xmalloc(sizeof(*ads)); + ads = SMB_XMALLOC_P(ADS_STRUCT); ZERO_STRUCTP(ads); - ads->server.realm = realm? strdup(realm) : NULL; - ads->server.workgroup = workgroup ? strdup(workgroup) : NULL; - ads->server.ldap_server = ldap_server? strdup(ldap_server) : NULL; + ads->server.realm = realm? SMB_STRDUP(realm) : NULL; + ads->server.workgroup = workgroup ? SMB_STRDUP(workgroup) : NULL; + ads->server.ldap_server = ldap_server? SMB_STRDUP(ldap_server) : NULL; /* we need to know if this is a foreign realm */ if (realm && *realm && !strequal(lp_realm(), realm)) { diff --git a/source3/libads/authdata.c b/source3/libads/authdata.c index 29170af377..ccaf82124c 100644 --- a/source3/libads/authdata.c +++ b/source3/libads/authdata.c @@ -59,7 +59,7 @@ static BOOL pac_io_unknown_type_10(const char *desc, UNKNOWN_TYPE_10 *type_10, return False; if (UNMARSHALLING(ps) && type_10->len) { - type_10->username = (uint16 *) prs_alloc_mem(ps, type_10->len); + type_10->username = PRS_ALLOC_MEM(ps, uint16, type_10->len); if (!type_10->username) { DEBUG(3, ("No memory available\n")); return False; @@ -85,8 +85,7 @@ static BOOL pac_io_krb_sids(const char *desc, KRB_SID_AND_ATTRS *sid_and_attr, depth++; if (UNMARSHALLING(ps)) { - sid_and_attr->sid = - (DOM_SID2 * ) prs_alloc_mem(ps, sizeof(DOM_SID2)); + sid_and_attr->sid = PRS_ALLOC_MEM(ps, DOM_SID2, 1); if (!sid_and_attr->sid) { DEBUG(3, ("No memory available\n")); return False; @@ -135,8 +134,7 @@ static BOOL pac_io_krb_sid_and_attr_array(const char *desc, return False; if (UNMARSHALLING(ps)) { - array->krb_sid_and_attrs = (KRB_SID_AND_ATTRS *) - prs_alloc_mem(ps, sizeof(KRB_SID_AND_ATTRS) * num); + array->krb_sid_and_attrs = PRS_ALLOC_MEM(ps, KRB_SID_AND_ATTRS, num); if (!array->krb_sid_and_attrs) { DEBUG(3, ("No memory available\n")); return False; @@ -199,8 +197,7 @@ static BOOL pac_io_group_membership_array(const char *desc, return False; if (UNMARSHALLING(ps)) { - array->group_membership = (GROUP_MEMBERSHIP *) - prs_alloc_mem(ps, sizeof(GROUP_MEMBERSHIP) * num); + array->group_membership = PRS_ALLOC_MEM(ps, GROUP_MEMBERSHIP, num); if (!array->group_membership) { DEBUG(3, ("No memory available\n")); return False; @@ -423,7 +420,7 @@ static BOOL pac_io_pac_signature_data(const char *desc, if (!prs_uint32("type", ps, depth, &data->type)) return False; if (UNMARSHALLING(ps)) { - data->signature = (unsigned char *)prs_alloc_mem(ps, siglen); + data->signature = PRS_ALLOC_MEM(ps, unsigned char, siglen); if (!data->signature) { DEBUG(3, ("No memory available\n")); return False; @@ -454,8 +451,7 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr, } if (UNMARSHALLING(ps) && hdr->size > 0) { - hdr->ctr = (PAC_INFO_CTR *) - prs_alloc_mem(ps, sizeof(PAC_INFO_CTR)); + hdr->ctr = PRS_ALLOC_MEM(ps, PAC_INFO_CTR, 1); if (!hdr->ctr) { DEBUG(3, ("No memory available\n")); return False; @@ -466,8 +462,7 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr, case PAC_TYPE_LOGON_INFO: DEBUG(5, ("PAC_TYPE_LOGON_INFO\n")); if (UNMARSHALLING(ps)) - hdr->ctr->pac.logon_info = (PAC_LOGON_INFO *) - prs_alloc_mem(ps, sizeof(PAC_LOGON_INFO)); + hdr->ctr->pac.logon_info = PRS_ALLOC_MEM(ps, PAC_LOGON_INFO, 1); if (!hdr->ctr->pac.logon_info) { DEBUG(3, ("No memory available\n")); return False; @@ -480,8 +475,7 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr, case PAC_TYPE_SERVER_CHECKSUM: DEBUG(5, ("PAC_TYPE_SERVER_CHECKSUM\n")); if (UNMARSHALLING(ps)) - hdr->ctr->pac.srv_cksum = (PAC_SIGNATURE_DATA *) - prs_alloc_mem(ps, sizeof(PAC_SIGNATURE_DATA)); + hdr->ctr->pac.srv_cksum = PRS_ALLOC_MEM(ps, PAC_SIGNATURE_DATA, 1); if (!hdr->ctr->pac.srv_cksum) { DEBUG(3, ("No memory available\n")); return False; @@ -494,8 +488,7 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr, case PAC_TYPE_PRIVSVR_CHECKSUM: DEBUG(5, ("PAC_TYPE_PRIVSVR_CHECKSUM\n")); if (UNMARSHALLING(ps)) - hdr->ctr->pac.privsrv_cksum = (PAC_SIGNATURE_DATA *) - prs_alloc_mem(ps, sizeof(PAC_SIGNATURE_DATA)); + hdr->ctr->pac.privsrv_cksum = PRS_ALLOC_MEM(ps, PAC_SIGNATURE_DATA, 1); if (!hdr->ctr->pac.privsrv_cksum) { DEBUG(3, ("No memory available\n")); return False; @@ -509,8 +502,7 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr, case PAC_TYPE_UNKNOWN_10: DEBUG(5, ("PAC_TYPE_UNKNOWN_10\n")); if (UNMARSHALLING(ps)) - hdr->ctr->pac.type_10 = (UNKNOWN_TYPE_10 *) - prs_alloc_mem(ps, sizeof(UNKNOWN_TYPE_10)); + hdr->ctr->pac.type_10 = PRS_ALLOC_MEM(ps, UNKNOWN_TYPE_10, 1); if (!hdr->ctr->pac.type_10) { DEBUG(3, ("No memory available\n")); return False; @@ -571,9 +563,7 @@ static BOOL pac_io_pac_data(const char *desc, PAC_DATA *data, return False; if (UNMARSHALLING(ps) && data->num_buffers > 0) { - if ((data->pac_info_hdr_ptr = (PAC_INFO_HDR *) - prs_alloc_mem(ps, sizeof(PAC_INFO_HDR) * - data->num_buffers)) == NULL) { + if ((data->pac_info_hdr_ptr = PRS_ALLOC_MEM(ps, PAC_INFO_HDR, data->num_buffers)) == NULL) { return False; } } @@ -606,7 +596,7 @@ PAC_DATA *decode_pac_data(DATA_BLOB *auth_data, TALLOC_CTX *ctx) data_blob_free(&pac_data_blob); - pac_data = (PAC_DATA *) talloc_zero(ctx, sizeof(PAC_DATA)); + pac_data = TALLOC_ZERO_P(ctx, PAC_DATA); pac_io_pac_data("pac data", pac_data, &ps, 0); prs_mem_free(&ps); diff --git a/source3/libads/kerberos_keytab.c b/source3/libads/kerberos_keytab.c index ec6a8c5078..8475f70ec4 100644 --- a/source3/libads/kerberos_keytab.c +++ b/source3/libads/kerberos_keytab.c @@ -546,7 +546,7 @@ int ads_keytab_create_default(ADS_STRUCT *ads) if (!found) { goto done; } - oldEntries = (char **) malloc(found * sizeof(char *)); + oldEntries = SMB_MALLOC_ARRAY(char *, found ); if (!oldEntries) { DEBUG(1,("ads_keytab_create_default: Failed to allocate space to store the old keytab entries (malloc failed?).\n")); ret = -1; diff --git a/source3/libads/kerberos_verify.c b/source3/libads/kerberos_verify.c index 848bd61acc..f7cbe8674b 100644 --- a/source3/libads/kerberos_verify.c +++ b/source3/libads/kerberos_verify.c @@ -174,7 +174,7 @@ static BOOL ads_secrets_verify_ticket(krb5_context context, krb5_auth_context au for (i=0;enctypes[i];i++) { krb5_keyblock *key = NULL; - if (!(key = (krb5_keyblock *)malloc(sizeof(*key)))) { + if (!(key = SMB_MALLOC_P(krb5_keyblock))) { goto out; } diff --git a/source3/libads/krb5_setpw.c b/source3/libads/krb5_setpw.c index 9582574851..dadce2593c 100644 --- a/source3/libads/krb5_setpw.c +++ b/source3/libads/krb5_setpw.c @@ -54,7 +54,7 @@ static DATA_BLOB encode_krb5_setpw(const char *principal, const char *password) DATA_BLOB ret; - princ = strdup(principal); + princ = SMB_STRDUP(principal); if ((c = strchr_m(princ, '/')) == NULL) { c = princ; @@ -156,7 +156,7 @@ static krb5_error_code build_kpasswd_request(uint16 pversion, return ret; } - packet->data = (char *)malloc(ap_req->length + cipherpw.length + 6); + packet->data = (char *)SMB_MALLOC(ap_req->length + cipherpw.length + 6); if (!packet->data) return -1; @@ -407,7 +407,7 @@ static ADS_STATUS do_krb5_kpasswd_request(krb5_context context, free(chpw_req.data); chpw_rep.length = 1500; - chpw_rep.data = (char *) malloc(chpw_rep.length); + chpw_rep.data = (char *) SMB_MALLOC(chpw_rep.length); if (!chpw_rep.data) { close(sock); free(ap_req.data); @@ -631,7 +631,7 @@ static ADS_STATUS ads_krb5_chg_password(const char *kdc_host, /* We have to obtain an INITIAL changepw ticket for changing password */ asprintf(&chpw_princ, "kadmin/changepw@%s", (char *) krb5_princ_realm(context, princ)); - password = strdup(oldpw); + password = SMB_STRDUP(oldpw); ret = krb5_get_init_creds_password(context, &creds, princ, password, kerb_prompter, NULL, 0, chpw_princ, &opts); diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 7bddc0e9b5..c18e253f7b 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -119,7 +119,7 @@ static BOOL ads_try_connect(ADS_STRUCT *ads, const char *server, unsigned port) DEBUG(5,("ads_try_connect: trying ldap server '%s' port %u\n", server, port)); /* this copes with inet_ntoa brokenness */ - srv = strdup(server); + srv = SMB_STRDUP(server); ads->ld = ldap_open_with_timeout(srv, port, lp_ldap_timeout()); if (!ads->ld) { @@ -296,11 +296,11 @@ got_connection: } if (!ads->auth.realm) { - ads->auth.realm = strdup(ads->config.realm); + ads->auth.realm = SMB_STRDUP(ads->config.realm); } if (!ads->auth.kdc_server) { - ads->auth.kdc_server = strdup(inet_ntoa(ads->ldap_ip)); + ads->auth.kdc_server = SMB_STRDUP(inet_ntoa(ads->ldap_ip)); } #if KRB5_DNS_HACK @@ -338,13 +338,13 @@ static struct berval *dup_berval(TALLOC_CTX *ctx, const struct berval *in_val) if (!in_val) return NULL; - value = talloc_zero(ctx, sizeof(struct berval)); + value = TALLOC_ZERO_P(ctx, struct berval); if (value == NULL) return NULL; if (in_val->bv_len == 0) return value; value->bv_len = in_val->bv_len; - value->bv_val = talloc_memdup(ctx, in_val->bv_val, in_val->bv_len); + value->bv_val = TALLOC_MEMDUP(ctx, in_val->bv_val, in_val->bv_len); return value; } @@ -358,9 +358,9 @@ static struct berval **ads_dup_values(TALLOC_CTX *ctx, int i; if (!in_vals) return NULL; - for (i=0; in_vals[i]; i++); /* count values */ - values = (struct berval **) talloc_zero(ctx, - (i+1)*sizeof(struct berval *)); + for (i=0; in_vals[i]; i++) + ; /* count values */ + values = TALLOC_ZERO_ARRAY(ctx, struct berval *, i+1); if (!values) return NULL; for (i=0; in_vals[i]; i++) { @@ -378,8 +378,9 @@ static char **ads_push_strvals(TALLOC_CTX *ctx, const char **in_vals) int i; if (!in_vals) return NULL; - for (i=0; in_vals[i]; i++); /* count values */ - values = (char ** ) talloc_zero(ctx, (i+1)*sizeof(char *)); + for (i=0; in_vals[i]; i++) + ; /* count values */ + values = TALLOC_ZERO_ARRAY(ctx, char *, i+1); if (!values) return NULL; for (i=0; in_vals[i]; i++) { @@ -397,8 +398,9 @@ static char **ads_pull_strvals(TALLOC_CTX *ctx, const char **in_vals) int i; if (!in_vals) return NULL; - for (i=0; in_vals[i]; i++); /* count values */ - values = (char **) talloc_zero(ctx, (i+1)*sizeof(char *)); + for (i=0; in_vals[i]; i++) + ; /* count values */ + values = TALLOC_ZERO_ARRAY(ctx, char *, i+1); if (!values) return NULL; for (i=0; in_vals[i]; i++) { @@ -824,8 +826,7 @@ ADS_MODLIST ads_init_mods(TALLOC_CTX *ctx) #define ADS_MODLIST_ALLOC_SIZE 10 LDAPMod **mods; - if ((mods = (LDAPMod **) talloc_zero(ctx, sizeof(LDAPMod *) * - (ADS_MODLIST_ALLOC_SIZE + 1)))) + if ((mods = TALLOC_ZERO_ARRAY(ctx, LDAPMod *, ADS_MODLIST_ALLOC_SIZE + 1))) /* -1 is safety to make sure we don't go over the end. need to reset it to NULL before doing ldap modify */ mods[ADS_MODLIST_ALLOC_SIZE] = (LDAPMod *) -1; @@ -861,8 +862,8 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods, for (curmod=0; modlist[curmod] && modlist[curmod] != (LDAPMod *) -1; curmod++); if (modlist[curmod] == (LDAPMod *) -1) { - if (!(modlist = talloc_realloc(ctx, modlist, - (curmod+ADS_MODLIST_ALLOC_SIZE+1)*sizeof(LDAPMod *)))) + if (!(modlist = TALLOC_REALLOC_ARRAY(ctx, modlist, LDAPMod *, + curmod+ADS_MODLIST_ALLOC_SIZE+1))) return ADS_ERROR(LDAP_NO_MEMORY); memset(&modlist[curmod], 0, ADS_MODLIST_ALLOC_SIZE*sizeof(LDAPMod *)); @@ -870,7 +871,7 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods, *mods = modlist; } - if (!(modlist[curmod] = talloc_zero(ctx, sizeof(LDAPMod)))) + if (!(modlist[curmod] = TALLOC_ZERO_P(ctx, LDAPMod))) return ADS_ERROR(LDAP_NO_MEMORY); modlist[curmod]->mod_type = talloc_strdup(ctx, name); if (mod_op & LDAP_MOD_BVALUES) { @@ -1046,11 +1047,11 @@ char *ads_ou_string(ADS_STRUCT *ads, const char *org_unit) ret = ads_default_ou_string(ads, WELL_KNOWN_GUID_COMPUTERS); /* samba4 might not yet respond to a wellknownobject-query */ - return ret ? ret : strdup("cn=Computers"); + return ret ? ret : SMB_STRDUP("cn=Computers"); } if (strequal(org_unit, "Computers")) { - return strdup("cn=Computers"); + return SMB_STRDUP("cn=Computers"); } return ads_build_path(org_unit, "\\/", "ou=", 1); @@ -1107,7 +1108,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid) for (i=1; i < new_ln; i++) { char *s; asprintf(&s, "%s,%s", ret, wkn_dn_exp[i]); - ret = strdup(s); + ret = SMB_STRDUP(s); free(s); } @@ -1741,7 +1742,7 @@ ADS_STATUS ads_join_realm(ADS_STRUCT *ads, const char *machine_name, char *machine; /* machine name must be lowercase */ - machine = strdup(machine_name); + machine = SMB_STRDUP(machine_name); strlower_m(machine); /* @@ -1791,7 +1792,7 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname) int rc; /* hostname must be lowercase */ - host = strdup(hostname); + host = SMB_STRDUP(hostname); strlower_m(host); status = ads_find_machine_acct(ads, &res, host); @@ -1915,7 +1916,7 @@ ADS_STATUS ads_set_machine_sd(ADS_STRUCT *ads, const char *hostname, char *dn) if (!(mods = ads_init_mods(ctx))) return ADS_ERROR(LDAP_NO_MEMORY); bval.bv_len = prs_offset(&ps_wire); - bval.bv_val = talloc(ctx, bval.bv_len); + bval.bv_val = TALLOC(ctx, bval.bv_len); if (!bval.bv_val) { ret = ADS_ERROR(LDAP_NO_MEMORY); goto ads_set_sd_error; @@ -2015,7 +2016,7 @@ char **ads_pull_strings(ADS_STRUCT *ads, *num_values = ldap_count_values(values); - ret = talloc(mem_ctx, sizeof(char *) * (*num_values+1)); + ret = TALLOC_ARRAY(mem_ctx, char *, *num_values + 1); if (!ret) { ldap_value_free(values); return NULL; @@ -2126,9 +2127,8 @@ char **ads_pull_strings_range(ADS_STRUCT *ads, return NULL; } - strings = talloc_realloc(mem_ctx, current_strings, - sizeof(*current_strings) * - (*num_strings + num_new_strings)); + strings = TALLOC_REALLOC_ARRAY(mem_ctx, current_strings, char *, + *num_strings + num_new_strings); if (strings == NULL) { ldap_memfree(range_attr); @@ -2265,7 +2265,7 @@ int ads_pull_sids(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, for (i=0; values[i]; i++) /* nop */ ; - (*sids) = talloc(mem_ctx, sizeof(DOM_SID) * i); + (*sids) = TALLOC_ARRAY(mem_ctx, DOM_SID, i); if (!(*sids)) { ldap_value_free_len(values); return 0; @@ -2446,7 +2446,7 @@ ADS_STATUS ads_server_info(ADS_STRUCT *ads) SAFE_FREE(ads->config.ldap_server_name); - ads->config.ldap_server_name = strdup(p+1); + ads->config.ldap_server_name = SMB_STRDUP(p+1); p = strchr(ads->config.ldap_server_name, '$'); if (!p || p[1] != '@') { talloc_destroy(ctx); @@ -2461,7 +2461,7 @@ ADS_STATUS ads_server_info(ADS_STRUCT *ads) SAFE_FREE(ads->config.realm); SAFE_FREE(ads->config.bind_path); - ads->config.realm = strdup(p+2); + ads->config.realm = SMB_STRDUP(p+2); ads->config.bind_path = ads_build_dn(ads->config.realm); DEBUG(3,("got ldap server name %s@%s, using bind path: %s\n", diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index d8e4cefcfa..68e6735891 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -161,10 +161,9 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, }; if (num_vals) { - str_values = talloc(ctx, - (num_vals + 1) * sizeof(smb_ucs2_t *)); + str_values = TALLOC_ARRAY(ctx, char *, num_vals + 1); memset(str_values, '\0', - (num_vals + 1) * sizeof(smb_ucs2_t *)); + (num_vals + 1) * sizeof(char *)); cur_str = (smb_ucs2_t *) value->data_p; for (i=0; i < num_vals; i++) diff --git a/source3/libads/ldap_utils.c b/source3/libads/ldap_utils.c index 991f16c845..03cdd339f0 100644 --- a/source3/libads/ldap_utils.c +++ b/source3/libads/ldap_utils.c @@ -42,7 +42,7 @@ ADS_STATUS ads_do_search_retry(ADS_STRUCT *ads, const char *bind_path, int scope return ADS_ERROR(LDAP_SERVER_DOWN); } - bp = strdup(bind_path); + bp = SMB_STRDUP(bind_path); if (!bp) { return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); diff --git a/source3/libads/sasl.c b/source3/libads/sasl.c index 8eb2c86bed..97ba9c9286 100644 --- a/source3/libads/sasl.c +++ b/source3/libads/sasl.c @@ -374,7 +374,7 @@ static ADS_STATUS ads_sasl_gssapi_bind(ADS_STRUCT *ads) gss_release_buffer(&minor_status, &output_token); - output_token.value = malloc(strlen(ads->config.bind_path) + 8); + output_token.value = SMB_MALLOC(strlen(ads->config.bind_path) + 8); p = output_token.value; *p++ = 1; /* no sign & seal selection */ |