r6445: Make us survive the PARANOID_MALLOC_CHECKER. Should we enable that for
authorVolker Lendecke <vlendec@samba.org>
Sat, 23 Apr 2005 18:07:01 +0000 (18:07 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:56:41 +0000 (10:56 -0500)
--enable-developer=yes?

Volker

source/auth/auth_util.c
source/auth/pampass.c
source/lib/util.c
source/passdb/pdb_ldap.c
source/passdb/pdb_nds.c
source/registry/reg_eventlog.c
source/rpc_client/cli_reg.c
source/rpc_parse/parse_eventlog.c
source/rpcclient/cmd_samr.c
source/sam/idmap_rid.c

index a50a449815c1314940a16f9f3db1f90d8d533041..30933c6c93820ea79be5cba22eb0b3e3ac0e7bef 100644 (file)
@@ -607,7 +607,7 @@ static NTSTATUS create_nt_user_token(const DOM_SID *user_sid, const DOM_SID *gro
                                                       group_sidstr, sidstr);
                }
 
-               command = strdup(lp_log_nt_token_command());
+               command = SMB_STRDUP(lp_log_nt_token_command());
                command = realloc_string_sub(command, "%s", user_sidstr);
                command = realloc_string_sub(command, "%t", group_sidstr);
                DEBUG(8, ("running command: [%s]\n", command));
index 68c2f183f17f202e9bd3b4b9d7984f94daf2b475..5a40bf6c4778ed572f13d3b5485d0cc026e2cb05 100644 (file)
@@ -130,7 +130,7 @@ static int smb_pam_conv(int num_msg,
                return PAM_CONV_ERR;
        }
 
-       reply = malloc(sizeof(struct pam_response) * num_msg);
+       reply = SMB_MALLOC_ARRAY(struct pam_response, num_msg);
        if (!reply)
                return PAM_CONV_ERR;
 
@@ -211,7 +211,7 @@ static struct chat_struct *make_pw_chat(char *p)
        struct chat_struct *tmp;
 
        while (1) {
-               t = (struct chat_struct *)malloc(sizeof(*t));
+               t = SMB_MALLOC_P(struct chat_struct);
                if (!t) {
                        DEBUG(0,("make_pw_chat: malloc failed!\n"));
                        return NULL;
@@ -290,7 +290,7 @@ static int smb_pam_passchange_conv(int num_msg,
                return PAM_CONV_ERR;
        }
 
-       reply = malloc(sizeof(struct pam_response) * num_msg);
+       reply = SMB_MALLOC_ARRAY(struct pam_response, num_msg);
        if (!reply) {
                DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
                free_pw_chat(pw_chat);
@@ -406,8 +406,8 @@ static void smb_free_pam_conv(struct pam_conv *pconv)
 static struct pam_conv *smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr, const char *user,
                                        const char *passwd, const char *newpass)
 {
-       struct pam_conv *pconv = (struct pam_conv *)malloc(sizeof(struct pam_conv));
-       struct smb_pam_userdata *udp = (struct smb_pam_userdata *)malloc(sizeof(struct smb_pam_userdata));
+       struct pam_conv *pconv = SMB_MALLOC_P(struct pam_conv);
+       struct smb_pam_userdata *udp = SMB_MALLOC_P(struct smb_pam_userdata);
 
        if (pconv == NULL || udp == NULL) {
                SAFE_FREE(pconv);
index 52cf15da1e489052e9107ef1f97e43e683d74576..77d4e6d2a67cec35904446057f63ff405962027f 100644 (file)
@@ -984,18 +984,22 @@ void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size,
                        void *element, void **array, uint32 *num_elements,
                        ssize_t *array_size)
 {
-       if (*array_size == -1)
+       if (*array_size < 0)
                return;
 
        if (*array == NULL) {
-               if (*array_size == 0)
+               if (*array_size == 0) {
                        *array_size = 128;
+               }
+
+               if (*array_size >= MAX_ALLOC_SIZE/element_size) {
+                       goto error;
+               }
 
                if (mem_ctx != NULL)
-                       *array = talloc_array(mem_ctx, element_size,
-                                             *array_size);
+                       *array = TALLOC(mem_ctx, element_size * (*array_size));
                else
-                       *array = malloc_array(element_size, *array_size);
+                       *array = SMB_MALLOC(element_size * (*array_size));
 
                if (*array == NULL)
                        goto error;
@@ -1004,13 +1008,16 @@ void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size,
        if (*num_elements == *array_size) {
                *array_size *= 2;
 
+               if (*array_size >= MAX_ALLOC_SIZE/element_size) {
+                       goto error;
+               }
+
                if (mem_ctx != NULL)
-                       *array = talloc_realloc_array(mem_ctx, *array,
-                                                     element_size,
-                                                     *array_size);
+                       *array = TALLOC_REALLOC(mem_ctx, *array,
+                                               element_size * (*array_size));
                else
-                       *array = realloc_array(*array, element_size,
-                                              *array_size);
+                       *array = SMB_REALLOC(*array,
+                                            element_size * (*array_size));
 
                if (*array == NULL)
                        goto error;
index 7d66b0aaf046ccd7e07395b87e382ce8b6149052..7b3d84e43b344e1b09d537e91dcb5457c7e9d7db 100644 (file)
@@ -2343,7 +2343,7 @@ static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
                goto done;
        }
 
-       sid_filter = strdup("(&(objectClass=sambaSamAccount)(|");
+       sid_filter = SMB_STRDUP("(&(objectClass=sambaSamAccount)(|");
        if (sid_filter == NULL) {
                result = NT_STATUS_NO_MEMORY;
                goto done;
@@ -3170,7 +3170,7 @@ static NTSTATUS ldapsam_lookup_rids(struct pdb_methods *methods,
        for (i=0; i<num_rids; i++)
                (*attrs)[i] = SID_NAME_UNKNOWN;
 
-       allsids = strdup("");
+       allsids = SMB_STRDUP("");
        if (allsids == NULL) return NT_STATUS_NO_MEMORY;
 
        for (i=0; i<num_rids; i++) {
index 06060d4067a06fc2b10d2eb38a27022ec8c8b6f2..e2f3128fd5d97c7621f9444397ec8f7b18417ddf 100644 (file)
@@ -241,7 +241,7 @@ static int berDecodeLoginData(
        if(retData)
        {
                retOctStrLen = *retDataLen + 1;
-               retOctStr = (char *)malloc(retOctStrLen);
+               retOctStr = SMB_MALLOC(retOctStrLen);
                if(!retOctStr)
                {
                        err = LDAP_OPERATIONS_ERROR;
@@ -404,7 +404,7 @@ static int nmasldap_get_simple_pwd(
        size_t  pwdBufLen, bufferLen;
 
        bufferLen = pwdBufLen = pwdLen+2;
-       pwdBuf = (char *)malloc(pwdBufLen); /* digest and null */
+       pwdBuf = SMB_MALLOC(pwdBufLen); /* digest and null */
        if(pwdBuf == NULL)
        {
                return LDAP_NO_MEMORY;
@@ -568,7 +568,7 @@ static int nmasldap_get_password(
        }
 
        bufferLen = pwdBufLen = *pwdSize;
-       pwdBuf = (char *)malloc(pwdBufLen+2);
+       pwdBuf = SMB_MALLOC(pwdBufLen+2);
        if(pwdBuf == NULL)
        {
                return LDAP_NO_MEMORY;
@@ -890,7 +890,7 @@ static NTSTATUS pdb_init_NDS_ldapsam_common(PDB_CONTEXT *pdb_context, PDB_METHOD
        (*pdb_method)->update_login_attempts = pdb_nds_update_login_attempts;
 
        /* Save location for use in pdb_nds_update_login_attempts */
-       ldap_state->location = strdup(location);
+       ldap_state->location = SMB_STRDUP(location);
 
        return NT_STATUS_OK;
 }
index cc2ffb5a0578c77044c6729aafa6e02485180c18..ccac7a190edf98bac0ea55805d24d2089f8b9c1f 100644 (file)
@@ -40,7 +40,7 @@ static int eventlog_topkey_values( char *key, REGVAL_CTR *val )
     
     if ( key ) 
     {
-       key2 = strdup( key );
+       key2 = SMB_STRDUP( key );
        keystr = key2;
        reg_split_path( keystr, &base, &new_path );
        
index 0d7d194850c91608fcfd51d4cceebc82ade6617c..87b41d248e201488f4f0e0bdfe8dc7da8a9ae807 100644 (file)
@@ -449,7 +449,7 @@ WERROR cli_reg_get_key_sec(struct cli_state *cli, TALLOC_CTX *mem_ctx,
 
        if (*sec_buf_size != 0)
        {
-               sec_buf->sec = (SEC_DESC*)talloc(mem_ctx, *sec_buf_size);
+               sec_buf->sec = TALLOC(mem_ctx, *sec_buf_size);
        }
 
        if (!reg_io_r_get_key_sec("", &r_o, &rbuf, 0))
index 9bb0a131697b3322e323b4a9b879f876d600ffc3..be21f0f74e8a0bfa907afb046f20e34653d3e17f 100644 (file)
@@ -372,7 +372,9 @@ BOOL eventlog_io_r_read_eventlog(const char *desc,
 
        /* Now pad with whitespace until the end of the response buffer */
 
-       r_u->end_of_entries_padding = (uint8 *)calloc(q_u->max_read_size - r_u->num_bytes_in_resp, sizeof(uint8));
+       r_u->end_of_entries_padding =
+               SMB_CALLOC_ARRAY(uint8,
+                                q_u->max_read_size - r_u->num_bytes_in_resp);
 
        if(!(prs_uint8s(False, "end of entries padding", ps, 
                depth, r_u->end_of_entries_padding,
index 53019dc1b2335c663c2f7534f74b637a2dda2fbe..bd150f2a353a7a8beb4000c83796be21f3c001f7 100644 (file)
@@ -145,19 +145,19 @@ static const char* server_role_str(uint32 server_role)
 {
        switch(server_role) {
                case ROLE_STANDALONE:
-                       return strdup("ROLE_STANDALONE");
+                       return SMB_STRDUP("ROLE_STANDALONE");
                        break;
                case ROLE_DOMAIN_MEMBER:
-                       return strdup("ROLE_DOMAIN_MEMBER");
+                       return SMB_STRDUP("ROLE_DOMAIN_MEMBER");
                        break;
                case ROLE_DOMAIN_BDC:
-                       return strdup("ROLE_DOMAIN_BDC");
+                       return SMB_STRDUP("ROLE_DOMAIN_BDC");
                        break;
                case ROLE_DOMAIN_PDC:
-                       return strdup("ROLE_DOMAIN_PDC");
+                       return SMB_STRDUP("ROLE_DOMAIN_PDC");
                        break;
                default:
-                       return strdup("Unknown -- internal error?");
+                       return SMB_STRDUP("Unknown -- internal error?");
                        break;
        }
 }
index 48e496b4b7a99ccbdac79dab69545fab475abe21..4f28f9e1af10bd15f7a3488d84d81edf947ec689 100644 (file)
@@ -81,7 +81,8 @@ static NTSTATUS rid_idmap_parse(const char *init_param,
                DEBUG(3,("rid_idmap_parse: parsing entry: %d\n", trust.number));
 
                /* reinit sizes */
-               trust.dom = (struct dom_entry *) realloc(trust.dom, sizeof(struct dom_entry)*(trust.number+1));
+               trust.dom = SMB_REALLOC_ARRAY(trust.dom, struct dom_entry,
+                                             trust.number+1);
 
                if ( trust.dom == NULL ) {
                        return NT_STATUS_NO_MEMORY;
@@ -163,8 +164,8 @@ static NTSTATUS rid_idmap_get_domains(uint32 *num_domains, fstring **domain_name
 
        /* put the results together */
        *num_domains = 1;
-       *domain_names = (fstring *) malloc(sizeof(fstring) * *num_domains);
-       *domain_sids = (DOM_SID *) malloc(sizeof(DOM_SID) * *num_domains); 
+       *domain_names = SMB_MALLOC_ARRAY(fstring, *num_domains);
+       *domain_sids = SMB_MALLOC_ARRAY(DOM_SID, *num_domains);
 
        /* avoid calling a DC when trusted domains are not allowed anyway */
        if (!lp_allow_trusted_domains()) {
@@ -276,8 +277,9 @@ static NTSTATUS rid_idmap_get_domains(uint32 *num_domains, fstring **domain_name
 
        /* put the results together */
        *num_domains = trusted_num_domains + own_domains;
-       *domain_names = (fstring *) realloc(*domain_names, sizeof(fstring) * *num_domains);
-       *domain_sids = (DOM_SID *) realloc(*domain_sids, sizeof(DOM_SID) * *num_domains); 
+       *domain_names = SMB_REALLOC_ARRAY(*domain_names, fstring,
+                                         *num_domains);
+       *domain_sids = SMB_REALLOC_ARRAY(*domain_sids, DOM_SID, *num_domains);
 
        /* first add mydomain */
        fstrcpy((*domain_names)[0], domain_name);
@@ -352,7 +354,7 @@ static NTSTATUS rid_idmap_init(char *init_param)
        }
 
        /* init sizes */
-       trust.dom = (struct dom_entry *) malloc(sizeof(struct dom_entry));
+       trust.dom = SMB_MALLOC_P(struct dom_entry);
        if (trust.dom == NULL) { 
                return NT_STATUS_NO_MEMORY;
        }