View | Details | Raw Unified | Return to bug 64119
Collapse All | Expand All

(-)samba-2.2.12-pre-CAN-2004-1154/examples/VFS/block/block.c (-6 / +6 lines)
Lines 209-215 Link Here
209
	
209
	
210
	if(pblock_mountp == NULL)
210
	if(pblock_mountp == NULL)
211
	{
211
	{
212
		pblock_mountp = calloc(1, sizeof(block_dir));
212
		pblock_mountp = SMB_CALLOC_ARRAY( block_dir, 1 );
213
		if( pblock_mountp == NULL)
213
		if( pblock_mountp == NULL)
214
		{
214
		{
215
			return FALSE;
215
			return FALSE;
Lines 219-225 Link Here
219
		
219
		
220
	}else
220
	}else
221
	{
221
	{
222
		tmp_pblock->next = calloc(1, sizeof(block_dir));
222
		tmp_pblock->next = SMB_CALLOC_ARRAY( block_dir, 1 );
223
		if(tmp_pblock->next == NULL)
223
		if(tmp_pblock->next == NULL)
224
		{
224
		{
225
			return FALSE;
225
			return FALSE;
Lines 231-237 Link Here
231
	
231
	
232
232
233
	tmp_pblock->st_dev = stat_buf.st_dev;
233
	tmp_pblock->st_dev = stat_buf.st_dev;
234
	tmp_pblock->dir_name = strdup(dir);
234
	tmp_pblock->dir_name = SMB_STRDUP(dir);
235
	
235
	
236
236
237
      return TRUE;
237
      return TRUE;
Lines 251-257 Link Here
251
251
252
	if(pblock_dir == NULL)
252
	if(pblock_dir == NULL)
253
	{
253
	{
254
		pblock_dir = calloc(1, sizeof(block_dir));
254
		pblock_dir = SMB_CALLOC_ARRAY( block_dir, 1 );
255
		if( pblock_dir == NULL)
255
		if( pblock_dir == NULL)
256
		{
256
		{
257
			return FALSE;
257
			return FALSE;
Lines 261-267 Link Here
261
		
261
		
262
	}else
262
	}else
263
	{
263
	{
264
		tmp_pblock->next = calloc(1, sizeof(block_dir));
264
		tmp_pblock->next = SMB_CALLOC_ARRAY( block_dir, 1 );
265
		if(tmp_pblock->next == NULL)
265
		if(tmp_pblock->next == NULL)
266
		{
266
		{
267
			return FALSE;
267
			return FALSE;
Lines 272-278 Link Here
272
	}
272
	}
273
	
273
	
274
274
275
	tmp_pblock->dir_name = strdup(dir);
275
	tmp_pblock->dir_name = SMB_STRDUP(dir);
276
	tmp_pblock->str_len = strlen(dir);
276
	tmp_pblock->str_len = strlen(dir);
277
	
277
	
278
278
(-)samba-2.2.12-pre-CAN-2004-1154/examples/VFS/recycle/recycle.c (-2 / +2 lines)
Lines 151-157 Link Here
151
static BOOL do_parameter(char *pszParmName, char *pszParmValue)
151
static BOOL do_parameter(char *pszParmName, char *pszParmValue)
152
{
152
{
153
	if (StrCaseCmp("name",pszParmName)==0) {
153
	if (StrCaseCmp("name",pszParmName)==0) {
154
		current->recycle_bin = (char *)talloc(current->ctx,sizeof(pstring));
154
		current->recycle_bin = (char *)TALLOC(current->ctx,sizeof(pstring));
155
		if (current->recycle_bin == NULL)
155
		if (current->recycle_bin == NULL)
156
			return False;
156
			return False;
157
		current->recycle_bin = safe_strcpy(current->recycle_bin,pszParmValue,sizeof(pstring));
157
		current->recycle_bin = safe_strcpy(current->recycle_bin,pszParmValue,sizeof(pstring));
Lines 236-242 Link Here
236
		DEBUG(10,("Using configuration file %s\n",conf_file));
236
		DEBUG(10,("Using configuration file %s\n",conf_file));
237
	}
237
	}
238
	
238
	
239
	current = talloc(ctx,sizeof(recycle_bin_struct));
239
	current = TALLOC_P(ctx,recycle_bin_struct);
240
	if ( current == NULL) {
240
	if ( current == NULL) {
241
		DEBUG(0, ("Failed to allocate memory in VFS module recycle_bin\n"));
241
		DEBUG(0, ("Failed to allocate memory in VFS module recycle_bin\n"));
242
		return -1;
242
		return -1;
(-)samba-2.2.12-pre-CAN-2004-1154/source/aparser/parser.c (+11 lines)
Lines 1-4 Link Here
1
#include "parser.h"
1
#include "parser.h"
2
#include <limits.h>
2
3
3
/*******************************************************************
4
/*******************************************************************
4
 Attempt, if needed, to grow a data buffer.
5
 Attempt, if needed, to grow a data buffer.
Lines 44-49 Link Here
44
		 * If the current buffer size is bigger than the space needed, just 
45
		 * If the current buffer size is bigger than the space needed, just 
45
		 * double it, else add extra_space.
46
		 * double it, else add extra_space.
46
		 */
47
		 */
48
		if(ps->buffer_size >= INT_MAX/2)
49
		{
50
			DEBUG(0,("io_grow: integer overflow detected.\n"));
51
			return False;
52
		}
53
		if(ps->buffer_size >= INT_MAX - extra_space)
54
		{
55
			DEBUG(0,("io_grow: integer overflow detected.\n"));
56
			return False;
57
		}
47
		new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);		
58
		new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);		
48
59
49
		if ((new_data = Realloc(ps->data_p, new_size)) == NULL) {
60
		if ((new_data = Realloc(ps->data_p, new_size)) == NULL) {
(-)samba-2.2.12-pre-CAN-2004-1154/source/client/client.c (-9 / +15 lines)
Lines 380-386 Link Here
380
{
380
{
381
	reset_do_list_queue();
381
	reset_do_list_queue();
382
	do_list_queue_size = 1024;
382
	do_list_queue_size = 1024;
383
	do_list_queue = malloc(do_list_queue_size);
383
	do_list_queue = SMB_MALLOC(do_list_queue_size);
384
	if (do_list_queue == 0) { 
384
	if (do_list_queue == 0) { 
385
		DEBUG(0,("malloc fail for size %d\n",
385
		DEBUG(0,("malloc fail for size %d\n",
386
			 (int)do_list_queue_size));
386
			 (int)do_list_queue_size));
Lines 421-430 Link Here
421
	long new_end = do_list_queue_end + ((long)strlen(entry)) + 1;
421
	long new_end = do_list_queue_end + ((long)strlen(entry)) + 1;
422
	while (new_end > do_list_queue_size)
422
	while (new_end > do_list_queue_size)
423
	{
423
	{
424
		if(do_list_queue_size >= INT_MAX/2)
425
		{
426
			DEBUG(0,("add_to_do_list_queue: integer overflow detected.\n"));
427
			reset_do_list_queue();
428
			return;
429
		}
424
		do_list_queue_size *= 2;
430
		do_list_queue_size *= 2;
425
		DEBUG(4,("enlarging do_list_queue to %d\n",
431
		DEBUG(4,("enlarging do_list_queue to %d\n",
426
			 (int)do_list_queue_size));
432
			 (int)do_list_queue_size));
427
		dlq = Realloc(do_list_queue, do_list_queue_size);
433
		dlq = SMB_REALLOC(do_list_queue, do_list_queue_size);
428
		if (!dlq) {
434
		if (!dlq) {
429
			DEBUG(0,("failure enlarging do_list_queue to %d bytes\n",
435
			DEBUG(0,("failure enlarging do_list_queue to %d bytes\n",
430
				(int)do_list_queue_size));
436
				(int)do_list_queue_size));
Lines 683-689 Link Here
683
	DEBUG(2,("getting file %s of size %.0f as %s ", 
689
	DEBUG(2,("getting file %s of size %.0f as %s ", 
684
		 rname, (double)size, lname));
690
		 rname, (double)size, lname));
685
691
686
	if(!(data = (char *)malloc(read_size))) { 
692
	if(!(data = (char *)SMB_MALLOC(read_size))) { 
687
		DEBUG(0,("malloc fail for size %d\n", read_size));
693
		DEBUG(0,("malloc fail for size %d\n", read_size));
688
		cli_close(cli, fnum);
694
		cli_close(cli, fnum);
689
		return;
695
		return;
Lines 1049-1055 Link Here
1049
	DEBUG(1,("putting file %s as %s ",lname,
1055
	DEBUG(1,("putting file %s as %s ",lname,
1050
		 rname));
1056
		 rname));
1051
  
1057
  
1052
	buf = (char *)malloc(maxwrite);
1058
	buf = (char *)SMB_MALLOC(maxwrite);
1053
	if (!buf) {
1059
	if (!buf) {
1054
		DEBUG(0, ("ERROR: Not enough memory!\n"));
1060
		DEBUG(0, ("ERROR: Not enough memory!\n"));
1055
		return;
1061
		return;
Lines 1249-1255 Link Here
1249
					return -1;
1255
					return -1;
1250
				}
1256
				}
1251
			}
1257
			}
1252
			entry = (struct file_list *) malloc(sizeof (struct file_list));
1258
			entry = SMB_MALLOC_P(struct file_list);
1253
			if (!entry) {
1259
			if (!entry) {
1254
				DEBUG(0,("Out of memory in file_find\n"));
1260
				DEBUG(0,("Out of memory in file_find\n"));
1255
				closedir(dir);
1261
				closedir(dir);
Lines 2045-2059 Link Here
2045
	/* for words not at the start of the line fallback to filename completion */
2051
	/* for words not at the start of the line fallback to filename completion */
2046
	if (start) return NULL;
2052
	if (start) return NULL;
2047
2053
2048
	matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
2054
	matches = SMB_MALLOC_ARRAY( char *, MAX_COMPLETIONS );
2049
	if (!matches) return NULL;
2055
	if (!matches) return NULL;
2050
2056
2051
	matches[count++] = strdup(text);
2057
	matches[count++] = SMB_STRDUP(text);
2052
	if (!matches[0]) return NULL;
2058
	if (!matches[0]) return NULL;
2053
2059
2054
	for (i=0;commands[i].fn && count < MAX_COMPLETIONS-1;i++) {
2060
	for (i=0;commands[i].fn && count < MAX_COMPLETIONS-1;i++) {
2055
		if (strncmp(text, commands[i].name, strlen(text)) == 0) {
2061
		if (strncmp(text, commands[i].name, strlen(text)) == 0) {
2056
			matches[count] = strdup(commands[i].name);
2062
			matches[count] = SMB_STRDUP(commands[i].name);
2057
			if (!matches[count]) return NULL;
2063
			if (!matches[count]) return NULL;
2058
			count++;
2064
			count++;
2059
		}
2065
		}
Lines 2061-2067 Link Here
2061
2067
2062
	if (count == 2) {
2068
	if (count == 2) {
2063
		SAFE_FREE(matches[0]);
2069
		SAFE_FREE(matches[0]);
2064
		matches[0] = strdup(matches[1]);
2070
		matches[0] = SMB_STRDUP(matches[1]);
2065
	}
2071
	}
2066
	matches[count] = NULL;
2072
	matches[count] = NULL;
2067
	return matches;
2073
	return matches;
(-)samba-2.2.12-pre-CAN-2004-1154/source/client/clitar.c (-18 / +42 lines)
Lines 109-115 Link Here
109
109
110
char tar_type='\0';
110
char tar_type='\0';
111
static char **cliplist=NULL;
111
static char **cliplist=NULL;
112
static int clipn=0;
112
static unsigned clipn=0;
113
static BOOL must_free_cliplist = False;
113
static BOOL must_free_cliplist = False;
114
114
115
extern file_info def_finfo;
115
extern file_info def_finfo;
Lines 149-159 Link Here
149
/*******************************************************************
149
/*******************************************************************
150
Create  a string of size size+1 (for the null)
150
Create  a string of size size+1 (for the null)
151
*******************************************************************/
151
*******************************************************************/
152
static char *string_create_s(int size)
152
static char *string_create_s(size_t size)
153
{
153
{
154
  char *tmp;
154
  char *tmp;
155
155
156
  tmp = (char *)malloc(size+1);
156
  tmp = (char *)SMB_MALLOC(size+1);
157
157
158
  if (tmp == NULL) {
158
  if (tmp == NULL) {
159
159
Lines 183-189 Link Here
183
  if (l >= NAMSIZ - 1) {
183
  if (l >= NAMSIZ - 1) {
184
	  /* write a GNU tar style long header */
184
	  /* write a GNU tar style long header */
185
	  char *b;
185
	  char *b;
186
	  b = (char *)malloc(l+TBLOCK+100);
186
187
	  if(l >= (INT_MAX - TBLOCK - 100)) {
188
		  DEBUG(0,("writetarheader: integer overflow detected.\n"));
189
	          exit(1);
190
	  }
191
	  b = (char *)SMB_MALLOC(l+TBLOCK+100);
187
	  if (!b) {
192
	  if (!b) {
188
		  DEBUG(0,("out of memory\n"));
193
		  DEBUG(0,("out of memory\n"));
189
		  exit(1);
194
		  exit(1);
Lines 384-391 Link Here
384
{
389
{
385
  /* initialize tar buffer */
390
  /* initialize tar buffer */
386
  tbufsiz=blocksize*TBLOCK;
391
  tbufsiz=blocksize*TBLOCK;
387
  tarbuf=malloc(tbufsiz);      /* FIXME: We might not get the buffer */
392
  tarbuf=SMB_MALLOC(tbufsiz);      /* FIXME: We might not get the buffer */
388
393
394
  if(tarbuf == NULL) {
395
    DEBUG(0,("initarbuf: out of memory.\n"));
396
    exit(1);
397
  }
389
  /* reset tar buffer pointer and tar file counter and total dumped */
398
  /* reset tar buffer pointer and tar file counter and total dumped */
390
  tp=0; ntarf=0; ttarf=0;
399
  tp=0; ntarf=0; ttarf=0;
391
}
400
}
Lines 1124-1134 Link Here
1124
*/
1133
*/
1125
static char * get_longfilename(file_info2 finfo)
1134
static char * get_longfilename(file_info2 finfo)
1126
{
1135
{
1127
  int namesize = strlen(finfo.name) + strlen(cur_dir) + 2;
1136
  size_t namesize;
1128
  char *longname = malloc(namesize);
1137
  char *longname;
1129
  SMB_BIG_INT offset = 0, left = finfo.size;
1138
  SMB_BIG_INT offset = 0, left = finfo.size;
1130
  BOOL first = True;
1139
  BOOL first = True;
1131
1140
1141
  if(strlen(finfo.name) >= (UINT_MAX - strlen(cur_dir) - 2)) {
1142
    DEBUG(0,("get_longfilename: integer overflow detected.\n"));
1143
    return NULL;
1144
  }
1145
  namesize = strlen(finfo.name) + strlen(cur_dir) + 2;
1146
  longname = SMB_MALLOC(namesize);
1132
  DEBUG(5, ("Restoring a long file name: %s\n", finfo.name));
1147
  DEBUG(5, ("Restoring a long file name: %s\n", finfo.name));
1133
  DEBUG(5, ("Len = %.0f\n", (double)finfo.size));
1148
  DEBUG(5, ("Len = %.0f\n", (double)finfo.size));
1134
1149
Lines 1576-1582 Link Here
1576
  FILE *inclusion = NULL;
1591
  FILE *inclusion = NULL;
1577
  char buf[MAXPATHLEN + 1];
1592
  char buf[MAXPATHLEN + 1];
1578
  char *inclusion_buffer = NULL;
1593
  char *inclusion_buffer = NULL;
1579
  int inclusion_buffer_size = 0;
1594
  size_t inclusion_buffer_size = 0;
1580
  int inclusion_buffer_sofar = 0;
1595
  int inclusion_buffer_sofar = 0;
1581
  char *p;
1596
  char *p;
1582
  char *tmpstr;
1597
  char *tmpstr;
Lines 1596-1602 Link Here
1596
  while ((! error) && (fgets(buf, sizeof(buf)-1, inclusion))) {
1611
  while ((! error) && (fgets(buf, sizeof(buf)-1, inclusion))) {
1597
    if (inclusion_buffer == NULL) {
1612
    if (inclusion_buffer == NULL) {
1598
      inclusion_buffer_size = 1024;
1613
      inclusion_buffer_size = 1024;
1599
      if ((inclusion_buffer = malloc(inclusion_buffer_size)) == NULL) {
1614
      if ((inclusion_buffer = SMB_MALLOC(inclusion_buffer_size)) == NULL) {
1600
	DEBUG(0,("failure allocating buffer to read inclusion file\n"));
1615
	DEBUG(0,("failure allocating buffer to read inclusion file\n"));
1601
	error = 1;
1616
	error = 1;
1602
	break;
1617
	break;
Lines 1609-1616 Link Here
1609
    
1624
    
1610
    if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) {
1625
    if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) {
1611
      char *ib;
1626
      char *ib;
1627
1628
      if(inclusion_buffer_size >= INT_MAX/2) {
1629
	DEBUG(0,("read_inclusion_file: integer overflow detected.\n"));
1630
	return 0;
1631
      }
1612
      inclusion_buffer_size *= 2;
1632
      inclusion_buffer_size *= 2;
1613
      ib = Realloc(inclusion_buffer,inclusion_buffer_size);
1633
      ib = SMB_REALLOC(inclusion_buffer,inclusion_buffer_size);
1614
      if (! ib) {
1634
      if (! ib) {
1615
        DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n", inclusion_buffer_size));
1635
        DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n", inclusion_buffer_size));
1616
        error = 1;
1636
        error = 1;
Lines 1621-1633 Link Here
1621
    
1641
    
1622
    safe_strcpy(inclusion_buffer + inclusion_buffer_sofar, buf, inclusion_buffer_size - inclusion_buffer_sofar);
1642
    safe_strcpy(inclusion_buffer + inclusion_buffer_sofar, buf, inclusion_buffer_size - inclusion_buffer_sofar);
1623
    inclusion_buffer_sofar += strlen(buf) + 1;
1643
    inclusion_buffer_sofar += strlen(buf) + 1;
1644
    if(clipn >= (INT_MAX-1)) {
1645
      DEBUG(0,("read_inclusion_file: integer overflow detected.\n"));
1646
      abort();
1647
    }
1624
    clipn++;
1648
    clipn++;
1625
  }
1649
  }
1626
  fclose(inclusion);
1650
  fclose(inclusion);
1627
1651
1628
  if (! error) {
1652
  if (! error) {
1629
    /* Allocate an array of clipn + 1 char*'s for cliplist */
1653
    /* Allocate an array of clipn + 1 char*'s for cliplist */
1630
    cliplist = malloc((clipn + 1) * sizeof(char *));
1654
    cliplist = SMB_MALLOC_ARRAY( char *, clipn + 1 );
1631
    if (cliplist == NULL) {
1655
    if (cliplist == NULL) {
1632
      DEBUG(0,("failure allocating memory for cliplist\n"));
1656
      DEBUG(0,("failure allocating memory for cliplist\n"));
1633
      error = 1;
1657
      error = 1;
Lines 1638-1644 Link Here
1638
	/* set current item to NULL so array will be null-terminated even if
1662
	/* set current item to NULL so array will be null-terminated even if
1639
	 * malloc fails below. */
1663
	 * malloc fails below. */
1640
	cliplist[i] = NULL;
1664
	cliplist[i] = NULL;
1641
	if ((tmpstr = (char *)malloc(strlen(p)+1)) == NULL) {
1665
	if ((tmpstr = (char *)SMB_MALLOC(strlen(p)+1)) == NULL) {
1642
	  DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", i));
1666
	  DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", i));
1643
	  error = 1;
1667
	  error = 1;
1644
	} else {
1668
	} else {
Lines 1797-1809 Link Here
1797
  } else if (Optind+1<argc && !tar_re_search) { /* For backwards compatibility */
1821
  } else if (Optind+1<argc && !tar_re_search) { /* For backwards compatibility */
1798
    char *tmpstr;
1822
    char *tmpstr;
1799
    char **tmplist;
1823
    char **tmplist;
1800
    int clipcount;
1824
    unsigned int clipcount;
1801
1825
1802
    cliplist=argv+Optind+1;
1826
    cliplist=argv+Optind+1;
1803
    clipn=argc-Optind-1;
1827
    clipn=argc-Optind-1;
1804
    clipcount = clipn;
1828
    clipcount = clipn;
1805
1829
1806
    if ((tmplist=malloc(clipn*sizeof(char *))) == NULL) {
1830
    if ((tmplist=SMB_MALLOC_ARRAY( char *, clipn )) == NULL) {
1807
      DEBUG(0, ("Could not allocate space to process cliplist, count = %i\n", 
1831
      DEBUG(0, ("Could not allocate space to process cliplist, count = %i\n", 
1808
               clipn)
1832
               clipn)
1809
           );
1833
           );
Lines 1814-1820 Link Here
1814
1838
1815
      DEBUG(5, ("Processing an item, %s\n", cliplist[clipcount]));
1839
      DEBUG(5, ("Processing an item, %s\n", cliplist[clipcount]));
1816
1840
1817
      if ((tmpstr = (char *)malloc(strlen(cliplist[clipcount])+1)) == NULL) {
1841
      if ((tmpstr = (char *)SMB_MALLOC(strlen(cliplist[clipcount])+1)) == NULL) {
1818
        DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n",
1842
        DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n",
1819
                 clipcount)
1843
                 clipcount)
1820
             );
1844
             );
Lines 1834-1843 Link Here
1834
#ifdef HAVE_REGEX_H
1858
#ifdef HAVE_REGEX_H
1835
    int errcode;
1859
    int errcode;
1836
1860
1837
    if ((preg = (regex_t *)malloc(65536)) == NULL) {
1861
    if ((preg = (regex_t *)SMB_MALLOC(65536)) == NULL) {
1838
1862
1839
      DEBUG(0, ("Could not allocate buffer for regular expression search\n"));
1863
      DEBUG(0, ("Could not allocate buffer for regular expression search\n"));
1840
      return;
1864
      return 0;
1841
1865
1842
    }
1866
    }
1843
1867
Lines 1848-1854 Link Here
1848
      errlen = regerror(errcode, preg, errstr, sizeof(errstr) - 1);
1872
      errlen = regerror(errcode, preg, errstr, sizeof(errstr) - 1);
1849
      
1873
      
1850
      DEBUG(0, ("Could not compile pattern buffer for re search: %s\n%s\n", argv[Optind + 1], errstr));
1874
      DEBUG(0, ("Could not compile pattern buffer for re search: %s\n%s\n", argv[Optind + 1], errstr));
1851
      return;
1875
      return 0;
1852
1876
1853
    }
1877
    }
1854
#endif
1878
#endif
(-)samba-2.2.12-pre-CAN-2004-1154/source/client/smbmnt.c (-1 / +1 lines)
Lines 104-110 Link Here
104
		fprintf(stderr,"Failed to find real path for mount point\n");
104
		fprintf(stderr,"Failed to find real path for mount point\n");
105
		exit(1);
105
		exit(1);
106
	}
106
	}
107
	return strdup(path);
107
	return SMB_STRDUP(path);
108
}
108
}
109
109
110
/* Check whether user is allowed to mount on the specified mount point. If it's
110
/* Check whether user is allowed to mount on the specified mount point. If it's
(-)samba-2.2.12-pre-CAN-2004-1154/source/client/smbumount.c (-2 / +2 lines)
Lines 134-140 Link Here
134
				npath = resolved_path;
134
				npath = resolved_path;
135
			else while(*(--npath) != '/');
135
			else while(*(--npath) != '/');
136
			m = strlen(path);
136
			m = strlen(path);
137
			if((buf = malloc(m + n + 1)) == NULL)
137
			if((buf = SMB_MALLOC(m + n + 1)) == NULL)
138
			{
138
			{
139
				fprintf(stderr,"Not enough memory.\n");
139
				fprintf(stderr,"Not enough memory.\n");
140
				return NULL;
140
				return NULL;
Lines 163-169 Link Here
163
static char *
163
static char *
164
canonicalize (char *path)
164
canonicalize (char *path)
165
{
165
{
166
	char *npath,*canonical = malloc (PATH_MAX + 1);
166
	char *npath,*canonical = SMB_MALLOC (PATH_MAX + 1);
167
	int i;
167
	int i;
168
168
169
	if (!canonical) {
169
	if (!canonical) {
(-)samba-2.2.12-pre-CAN-2004-1154/source/groupdb/aliasdb.c (-1 / +1 lines)
Lines 143-149 Link Here
143
	if (alss == NULL || num_alss == NULL || als == NULL)
143
	if (alss == NULL || num_alss == NULL || als == NULL)
144
		return False;
144
		return False;
145
145
146
	talss = (LOCAL_GRP *)Realloc((*alss), ((*num_alss)+1) * sizeof(LOCAL_GRP));
146
	talss = SMB_REALLOC_ARRAY( *alss, LOCAL_GRP, (*num_alss)+1 );
147
    if (talss == NULL) {
147
    if (talss == NULL) {
148
		if (*alss)
148
		if (*alss)
149
			free(*alss);
149
			free(*alss);
(-)samba-2.2.12-pre-CAN-2004-1154/source/groupdb/aliasfile.c (-1 / +1 lines)
Lines 129-135 Link Here
129
		uint8 type;
129
		uint8 type;
130
130
131
		if (lookup_sid(name, &sid, &type)) {
131
		if (lookup_sid(name, &sid, &type)) {
132
			mbrs = Realloc((*members), ((*num_mem)+1) * sizeof(LOCAL_GRP_MEMBER));
132
			mbrs = SMB_REALLOC_ARRAY( *members, LOCAL_GRP_MEMBER, (*num_mem)+1 );
133
			(*num_mem)++;
133
			(*num_mem)++;
134
		} else {
134
		} else {
135
			DEBUG(0,("alias database: could not resolve alias named %s\n", name));
135
			DEBUG(0,("alias database: could not resolve alias named %s\n", name));
(-)samba-2.2.12-pre-CAN-2004-1154/source/groupdb/groupdb.c (-1 / +1 lines)
Lines 141-147 Link Here
141
	if (grps == NULL || num_grps == NULL || grp == NULL)
141
	if (grps == NULL || num_grps == NULL || grp == NULL)
142
		return False;
142
		return False;
143
143
144
	tgrps = (DOMAIN_GRP *)Realloc((*grps), ((*num_grps)+1) * sizeof(DOMAIN_GRP));
144
	tgrps = SMB_REALLOC_ARRAY(*grps, DOMAIN_GRP, (*num_grps)+1 );
145
	if (tgrps == NULL) {
145
	if (tgrps == NULL) {
146
		if (*grps)
146
		if (*grps)
147
			free(*grps);
147
			free(*grps);
(-)samba-2.2.12-pre-CAN-2004-1154/source/groupdb/groupfile.c (-1 / +1 lines)
Lines 129-135 Link Here
129
	{
129
	{
130
		DOMAIN_GRP_MEMBER *mbrs;
130
		DOMAIN_GRP_MEMBER *mbrs;
131
131
132
		mbrs = (DOMAIN_GRP_MEMBER *)Realloc((*members), ((*num_mem)+1) * sizeof(DOMAIN_GRP_MEMBER));
132
		mbrs = SMB_REALLOC_ARRAY( *members, DOMAIN_GRP_MEMBER, (*num_mem)+1 );
133
		if (mbrs == NULL) {
133
		if (mbrs == NULL) {
134
			if (*members)
134
			if (*members)
135
				free(*members);
135
				free(*members);
(-)samba-2.2.12-pre-CAN-2004-1154/source/include/proto.h (-7 / +29 lines)
Lines 1068-1086 Link Here
1068
/* The following definitions come from lib/talloc.c  */
1068
/* The following definitions come from lib/talloc.c  */
1069
1069
1070
TALLOC_CTX *talloc_init(void);
1070
TALLOC_CTX *talloc_init(void);
1071
void *talloc(TALLOC_CTX *t, size_t size);
1072
void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size);
1073
void talloc_destroy_pool(TALLOC_CTX *t);
1071
void talloc_destroy_pool(TALLOC_CTX *t);
1074
void talloc_destroy(TALLOC_CTX *t);
1072
void talloc_destroy(TALLOC_CTX *t);
1075
size_t talloc_pool_size(TALLOC_CTX *t);
1073
size_t talloc_pool_size(TALLOC_CTX *t);
1076
const char * talloc_pool_name(TALLOC_CTX const *t);
1074
const char * talloc_pool_name(TALLOC_CTX const *t);
1077
void *talloc_zero(TALLOC_CTX *t, size_t size);
1078
void *talloc_memdup(TALLOC_CTX *t, const void *p, size_t size);
1079
char *talloc_strdup(TALLOC_CTX *t, const char *p);
1075
char *talloc_strdup(TALLOC_CTX *t, const char *p);
1080
char *talloc_describe_all(TALLOC_CTX *rt);
1076
char *talloc_describe_all(TALLOC_CTX *rt);
1081
void talloc_get_allocation(TALLOC_CTX *t,
1077
void talloc_get_allocation(TALLOC_CTX *t,
1082
			   size_t *total_bytes,
1078
			   size_t *total_bytes,
1083
			   int *n_chunks);
1079
			   int *n_chunks);
1080
#define PARANOID_MALLOC_CHECKER 1
1081
#if defined(PARANOID_MALLOC_CHECKER)
1082
extern void *talloc_(TALLOC_CTX *t, size_t size);
1083
extern void *talloc_realloc_ ( TALLOC_CTX *, void *, size_t );
1084
extern void *talloc_array_ ( TALLOC_CTX *, size_t, unsigned int );
1085
extern void *talloc_zero_(TALLOC_CTX *t, size_t size);
1086
extern void *talloc_zero_array_(TALLOC_CTX *t, size_t size, unsigned int);
1087
extern void *talloc_realloc_array_ ( TALLOC_CTX *, void *, size_t, unsigned int );
1088
extern void *talloc_memdup_(TALLOC_CTX *t, const void *p, size_t size);
1089
#else
1090
extern void *talloc(TALLOC_CTX *t, size_t size);
1091
extern void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size);
1092
extern void *talloc_zero(TALLOC_CTX *t, size_t size);
1093
extern void *talloc_zero_array ( TALLOC_CTX *, void *, size_t, unsigned int );
1094
extern void *talloc_array ( TALLOC_CTX *, void *, size_t, unsigned int );
1095
extern void *talloc_realloc_array(TALLOC_CTX *t, void *ptr, size_t size, unsigned int);
1096
extern void *talloc_memdup(TALLOC_CTX *t, const void *p, size_t size);
1097
#endif
1084
1098
1085
/* The following definitions come from lib/time.c  */
1099
/* The following definitions come from lib/time.c  */
1086
1100
Lines 1151-1157 Link Here
1151
void msleep(unsigned int t);
1165
void msleep(unsigned int t);
1152
void become_daemon(void);
1166
void become_daemon(void);
1153
BOOL yesno(char *p);
1167
BOOL yesno(char *p);
1154
void *Realloc(void *p,size_t size);
1155
void safe_free(void *p);
1168
void safe_free(void *p);
1156
BOOL get_myname(char *my_name);
1169
BOOL get_myname(char *my_name);
1157
int interpret_protocol(char *str,int def);
1170
int interpret_protocol(char *str,int def);
Lines 1189-1197 Link Here
1189
int set_maxfiles(int requested_max);
1202
int set_maxfiles(int requested_max);
1190
BOOL reg_split_key(const char *full_keyname, uint32 *reg_type, char *key_name);
1203
BOOL reg_split_key(const char *full_keyname, uint32 *reg_type, char *key_name);
1191
int smb_mkstemp(char *template);
1204
int smb_mkstemp(char *template);
1192
void *smb_xmalloc(size_t size);
1193
void *smb_xmemdup(const void *p, size_t size);
1205
void *smb_xmemdup(const void *p, size_t size);
1194
char *smb_xstrdup(const char *s);
1206
char *smb_xstrdup(const char *s);
1207
extern char *smb_xstrndup(const char *s, size_t );
1195
int smb_xvasprintf(char **ptr, const char *format, va_list ap);
1208
int smb_xvasprintf(char **ptr, const char *format, va_list ap);
1196
void *memdup(void *p, size_t size);
1209
void *memdup(void *p, size_t size);
1197
char *myhostname(void);
1210
char *myhostname(void);
Lines 1206-1211 Link Here
1206
void data_blob_free(DATA_BLOB *d);
1219
void data_blob_free(DATA_BLOB *d);
1207
void data_blob_clear(DATA_BLOB *d);
1220
void data_blob_clear(DATA_BLOB *d);
1208
int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6);
1221
int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6);
1222
#if defined(PARANOID_MALLOC_CHECKER)
1223
extern void *malloc_ ( size_t );
1224
#endif
1225
extern void *smb_malloc(void *p,size_t size);
1226
extern void *malloc_array ( size_t, unsigned int );
1227
extern void *calloc_array ( size_t, size_t );
1228
extern void *realloc_array ( void *, size_t, unsigned int );
1229
extern void *smb_xmalloc_array ( size_t, unsigned int );
1230
extern void *smb_realloc(void *p,size_t size);
1209
1231
1210
/* The following definitions come from lib/util_file.c  */
1232
/* The following definitions come from lib/util_file.c  */
1211
1233
Lines 2908-2914 Link Here
2908
BOOL prs_read(prs_struct *ps, int fd, size_t len, int timeout);
2930
BOOL prs_read(prs_struct *ps, int fd, size_t len, int timeout);
2909
void prs_mem_free(prs_struct *ps);
2931
void prs_mem_free(prs_struct *ps);
2910
void prs_mem_clear(prs_struct *ps);
2932
void prs_mem_clear(prs_struct *ps);
2911
char *prs_alloc_mem(prs_struct *ps, size_t size);
2912
TALLOC_CTX *prs_get_mem_context(prs_struct *ps);
2933
TALLOC_CTX *prs_get_mem_context(prs_struct *ps);
2913
void prs_give_memory(prs_struct *ps, char *buf, uint32 size, BOOL is_dynamic);
2934
void prs_give_memory(prs_struct *ps, char *buf, uint32 size, BOOL is_dynamic);
2914
char *prs_take_memory(prs_struct *ps, uint32 *psize);
2935
char *prs_take_memory(prs_struct *ps, uint32 *psize);
Lines 2955-2960 Link Here
2955
int tdb_prs_store(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps);
2976
int tdb_prs_store(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps);
2956
int tdb_prs_fetch(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps, TALLOC_CTX *mem_ctx);
2977
int tdb_prs_fetch(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps, TALLOC_CTX *mem_ctx);
2957
BOOL prs_hash1(prs_struct *ps, uint32 offset, uint8 sess_key[16]);
2978
BOOL prs_hash1(prs_struct *ps, uint32 offset, uint8 sess_key[16]);
2979
extern char *prs_alloc_mem_(prs_struct *ps, size_t size, size_t count );
2958
2980
2959
/* The following definitions come from rpc_parse/parse_reg.c  */
2981
/* The following definitions come from rpc_parse/parse_reg.c  */
2960
2982
(-)samba-2.2.12-pre-CAN-2004-1154/source/include/smb_macros.h (+88 lines)
Lines 284-287 Link Here
284
284
285
#define vfs_chdir(conn,fname) ((conn)->vfs_ops.chdir((conn),dos_to_unix_static((fname))))
285
#define vfs_chdir(conn,fname) ((conn)->vfs_ops.chdir((conn),dos_to_unix_static((fname))))
286
286
287
/*****************************************************************************
288
 Safe allocation macros.
289
*****************************************************************************/
290
291
#define SMB_MALLOC_ARRAY(type,count) (type *)malloc_array(sizeof(type),(count))
292
#define SMB_REALLOC(p,s) smb_realloc((p),(s))
293
#define SMB_REALLOC_ARRAY(p,type,count) (type *)realloc_array((p),sizeof(type),(count))
294
#define SMB_CALLOC_ARRAY(type,count) (type *)calloc_array(sizeof(type),(count))
295
#define SMB_XMALLOC_P(type) (type *)smb_xmalloc_array(sizeof(type),1)
296
#define SMB_XMALLOC_ARRAY(type,count) (type *)smb_xmalloc_array(sizeof(type),(count))
297
298
/* limiting size of ipc replies */
299
#define SMB_REALLOC_LIMIT(ptr,size) SMB_REALLOC(ptr,MAX((size),4*1024))
300
301
#define PARANOID_MALLOC_CHECKER 1
302
303
#if defined(PARANOID_MALLOC_CHECKER)
304
305
#define TALLOC(ctx, size) talloc_((ctx),(size))
306
#define TALLOC_P(ctx, type) (type *)talloc_((ctx),sizeof(type))
307
#define TALLOC_ARRAY(ctx, type, count) (type *)talloc_array_((ctx),sizeof(type),(count))
308
#define TALLOC_MEMDUP(ctx, ptr, size) talloc_memdup_((ctx),(ptr),(size))
309
#define TALLOC_ZERO(ctx, size) talloc_zero_((ctx),(size))
310
#define TALLOC_ZERO_P(ctx, type) (type *)talloc_zero_((ctx),sizeof(type))
311
#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)talloc_zero_array_((ctx),sizeof(type),(count))
312
#define TALLOC_REALLOC(ctx, ptr, count) talloc_realloc_((ctx),(ptr),(count))
313
#define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)talloc_realloc_array_((ctx),(ptr),sizeof(type),(count))
314
315
#define PRS_ALLOC_MEM(ps, type, count) (type *)talloc_zero_array_((ps)->mem_ctx,sizeof(type),(count))
316
317
/* Get medieval on our ass about malloc.... */
318
319
/* Restrictions on malloc/realloc/calloc. */
320
#ifdef malloc
321
#undef malloc
322
#endif
323
#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY
324
325
#ifdef realloc
326
#undef realloc
327
#endif
328
#define realloc(p,s) __ERROR_DONT_USE_REALLOC_DIRECTLY
329
330
#ifdef calloc
331
#undef calloc
332
#endif
333
#define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY
334
335
#ifdef strndup
336
#undef strndup
337
#endif
338
#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY
339
340
#ifdef strdup
341
#undef strdup
342
#endif
343
#define strdup(s) __ERROR_DONT_USE_STRDUP_DIRECTLY
344
345
#define SMB_MALLOC(s) malloc_(s)
346
#define SMB_MALLOC_P(type) (type *)malloc_(sizeof(type))
347
348
#define SMB_STRDUP(s) smb_xstrdup(s)
349
#define SMB_STRNDUP(s,n) smb_xstrndup(s,n)
350
351
#else /* PARANOID_MEMORY_CHECKER disabled */
352
353
#define TALLOC(ctx, size) talloc((ctx),(size))
354
#define TALLOC_P(ctx, type) (type *)talloc((ctx),sizeof(type))
355
#define TALLOC_ARRAY(ctx, type, count) (type *)talloc_array((ctx),sizeof(type),(count))
356
#define TALLOC_MEMDUP(ctx, ptr, size) talloc_memdup((ctx),(ptr),(size))
357
#define TALLOC_ZERO(ctx, size) talloc_zero((ctx),(size))
358
#define TALLOC_ZERO_P(ctx, type) (type *)talloc_zero((ctx),sizeof(type))
359
#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)talloc_zero_array((ctx),sizeof(type),(count))
360
#define TALLOC_REALLOC(ctx, ptr, count) talloc_realloc((ctx),(ptr),(count))
361
#define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)talloc_realloc_array((ctx),(ptr),sizeof(type),(count))
362
363
#define PRS_ALLOC_MEM(ps, type, count) (type *)prs_alloc_mem((ps),sizeof(type),(count))
364
365
/* Regular malloc code. */
366
367
#define SMB_MALLOC(s) malloc(s)
368
#define SMB_MALLOC_P(type) (type *)malloc(sizeof(type))
369
370
#define SMB_STRDUP(s) strdup(s)
371
#define SMB_STRNDUP(s,n) strndup(s,n)
372
373
#endif /* not PARANOID_MEMORY_CHECKER */
374
287
#endif /* _SMB_MACROS_H */
375
#endif /* _SMB_MACROS_H */
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/access.c (-5 / +5 lines)
Lines 81-87 Link Here
81
			DEBUG(0,("Unable to get default yp domain.\n"));
81
			DEBUG(0,("Unable to get default yp domain.\n"));
82
			return False;
82
			return False;
83
		}
83
		}
84
		if (!(hostname = strdup(s))) {
84
		if (!(hostname = SMB_STRDUP(s))) {
85
			DEBUG(1,("out of memory for strdup!\n"));
85
			DEBUG(1,("out of memory for strdup!\n"));
86
			return False;
86
			return False;
87
		}
87
		}
Lines 167-173 Link Here
167
     */
167
     */
168
168
169
    /* jkf -- can get called recursively with NULL list */
169
    /* jkf -- can get called recursively with NULL list */
170
    listcopy = (list == 0) ? (char *)0 : strdup(list);
170
    listcopy = (list == 0) ? (char *)0 : SMB_STRDUP(list);
171
171
172
    /*
172
    /*
173
     * Process tokens one at a time. We have exhausted all possible matches
173
     * Process tokens one at a time. We have exhausted all possible matches
Lines 259-265 Link Here
259
	char		*listcopy,
259
	char		*listcopy,
260
			*tok;
260
			*tok;
261
			
261
			
262
	listcopy = strdup(list);
262
	listcopy = SMB_STRDUP(list);
263
263
264
	for (tok = strtok(listcopy, sep); tok ; tok = strtok(NULL, sep)) 
264
	for (tok = strtok(listcopy, sep); tok ; tok = strtok(NULL, sep)) 
265
	{
265
	{
Lines 304-312 Link Here
304
		deny_list ? deny_list : "NULL"));
304
		deny_list ? deny_list : "NULL"));
305
305
306
	if (deny_list) 
306
	if (deny_list) 
307
		deny = strdup(deny_list);
307
		deny = SMB_STRDUP(deny_list);
308
	if (allow_list) 
308
	if (allow_list) 
309
		allow = strdup(allow_list);
309
		allow = SMB_STRDUP(allow_list);
310
310
311
	if ((!deny || *deny==0) && (!allow || *allow==0))
311
	if ((!deny || *deny==0) && (!allow || *allow==0))
312
		ret = True;
312
		ret = True;
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/bitmap.c (-4 / +4 lines)
Lines 32-49 Link Here
32
{
32
{
33
	struct bitmap *bm;
33
	struct bitmap *bm;
34
34
35
	bm = (struct bitmap *)malloc(sizeof(*bm));
35
	bm = SMB_MALLOC_P(struct bitmap);
36
36
37
	if (!bm) return NULL;
37
	if (!bm) return NULL;
38
	
38
	
39
	bm->n = n;
39
	bm->n = n;
40
	bm->b = (uint32 *)malloc(sizeof(bm->b[0])*(n+31)/32);
40
	bm->b = SMB_MALLOC_ARRAY( uint32, (n+31)/32 );
41
	if (!bm->b) {
41
	if (!bm->b) {
42
		SAFE_FREE(bm);
42
		SAFE_FREE(bm);
43
		return NULL;
43
		return NULL;
44
	}
44
	}
45
45
46
	memset(bm->b, 0, sizeof(bm->b[0])*(n+31)/32);
46
	memset(bm->b, 0, sizeof(uint32)*((n+31)/32));
47
47
48
	return bm;
48
	return bm;
49
}
49
}
Lines 70-76 Link Here
70
        int count = MIN(dst->n, src->n);
70
        int count = MIN(dst->n, src->n);
71
71
72
        SMB_ASSERT(dst->b != src->b);
72
        SMB_ASSERT(dst->b != src->b);
73
	memcpy(dst->b, src->b, sizeof(dst->b[0])*(count+31)/32);
73
	memcpy(dst->b, src->b, sizeof(uint32)*((count+31)/32));
74
74
75
        return count;
75
        return count;
76
}
76
}
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/charset.c (-2 / +2 lines)
Lines 287-293 Link Here
287
  }
287
  }
288
288
289
  /* Allocate space for the code page file and read it all in. */
289
  /* Allocate space for the code page file and read it all in. */
290
  if((cp_p = (codepage_p)malloc( size  + 4 )) == NULL)
290
  if((cp_p = (codepage_p)SMB_MALLOC( size  + 4 )) == NULL)
291
  {
291
  {
292
    DEBUG(0,("load_client_codepage: malloc fail.\n"));
292
    DEBUG(0,("load_client_codepage: malloc fail.\n"));
293
    goto clean_and_exit;
293
    goto clean_and_exit;
Lines 378-384 Link Here
378
********************************************************************/
378
********************************************************************/
379
void add_char_string(const char *s)
379
void add_char_string(const char *s)
380
{
380
{
381
  char *extra_chars = (char *)strdup(s);
381
  char *extra_chars = SMB_STRDUP(s);
382
  char *t;
382
  char *t;
383
  if (!extra_chars) return;
383
  if (!extra_chars) return;
384
384
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/hash.c (-2 / +2 lines)
Lines 67-73 Link Here
67
67
68
	DEBUG(5, ("Hash size = %d.\n", table->size));
68
	DEBUG(5, ("Hash size = %d.\n", table->size));
69
69
70
	if(!(table->buckets = (ubi_dlList *) malloc(sizeof(ubi_dlList) * table->size))) {
70
	if(!(table->buckets = SMB_MALLOC_ARRAY( ubi_dlList, table->size ))) {
71
		DEBUG(0,("hash_table_init: malloc fail !\n"));
71
		DEBUG(0,("hash_table_init: malloc fail !\n"));
72
		return False;
72
		return False;
73
	}
73
	}
Lines 207-213 Link Here
207
	 */
207
	 */
208
208
209
	string_length = strlen(key);
209
	string_length = strlen(key);
210
	if(!(hash_elem = (hash_element *) malloc(sizeof(hash_element) + string_length))) {
210
	if(!(hash_elem = (hash_element *) SMB_MALLOC(sizeof(hash_element) + string_length))) {
211
		DEBUG(0,("hash_insert: malloc fail !\n"));
211
		DEBUG(0,("hash_insert: malloc fail !\n"));
212
		return (hash_element *)NULL;
212
		return (hash_element *)NULL;
213
	}
213
	}
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/interface.c (-1 / +1 lines)
Lines 67-73 Link Here
67
		return;
67
		return;
68
	}
68
	}
69
69
70
	iface = (struct interface *)malloc(sizeof(*iface));
70
	iface = SMB_MALLOC_P(struct interface);
71
	if (!iface) return;
71
	if (!iface) return;
72
	
72
	
73
	ZERO_STRUCTPN(iface);
73
	ZERO_STRUCTPN(iface);
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/messages.c (-4 / +8 lines)
Lines 183-189 Link Here
183
183
184
	if (!dbuf.dptr) {
184
	if (!dbuf.dptr) {
185
		/* its a new record */
185
		/* its a new record */
186
		p = (void *)malloc(len + sizeof(rec));
186
		p = (void *)SMB_MALLOC(len + sizeof(rec));
187
		if (!p) goto failed;
187
		if (!p) goto failed;
188
188
189
		memcpy(p, &rec, sizeof(rec));
189
		memcpy(p, &rec, sizeof(rec));
Lines 221-227 Link Here
221
	}
221
	}
222
222
223
	/* we're adding to an existing entry */
223
	/* we're adding to an existing entry */
224
	p = (void *)malloc(dbuf.dsize + len + sizeof(rec));
224
	if(dbuf.dsize >= (INT_MAX-len) || (dbuf.dsize+len) > (INT_MAX-sizeof(rec))) {
225
		DEBUG(0,("message_send_pid: integer overflow detected.\n"));
226
		goto failed;
227
	}
228
	p = (void *)SMB_MALLOC(dbuf.dsize + len + sizeof(rec));
225
	if (!p) goto failed;
229
	if (!p) goto failed;
226
230
227
	memcpy(p, dbuf.dptr, dbuf.dsize);
231
	memcpy(p, dbuf.dptr, dbuf.dsize);
Lines 270-276 Link Here
270
	}
274
	}
271
275
272
	if (rec.len > 0) {
276
	if (rec.len > 0) {
273
		(*buf) = (void *)malloc(rec.len);
277
		(*buf) = (void *)SMB_MALLOC(rec.len);
274
		if (!(*buf)) goto failed;
278
		if (!(*buf)) goto failed;
275
279
276
		memcpy(*buf, dbuf.dptr+sizeof(rec), rec.len);
280
		memcpy(*buf, dbuf.dptr+sizeof(rec), rec.len);
Lines 350-356 Link Here
350
{
354
{
351
	struct dispatch_fns *dfn;
355
	struct dispatch_fns *dfn;
352
356
353
	dfn = (struct dispatch_fns *)malloc(sizeof(*dfn));
357
	dfn = SMB_MALLOC_P(struct dispatch_fns);
354
358
355
	if (dfn != NULL) {
359
	if (dfn != NULL) {
356
360
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/ms_fnmatch.c (-1 / +1 lines)
Lines 220-226 Link Here
220
	}
220
	}
221
221
222
	if (count != 0) {
222
	if (count != 0) {
223
		max_n = calloc(sizeof(struct max_n), count);
223
		max_n = SMB_CALLOC_ARRAY( struct max_n, count );
224
		if (!max_n) {
224
		if (!max_n) {
225
		return -1;
225
		return -1;
226
		}
226
		}
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/sysacls.c (-2 / +2 lines)
Lines 697-703 Link Here
697
697
698
			maxlen += nbytes + 20 * (acl_d->count - i);
698
			maxlen += nbytes + 20 * (acl_d->count - i);
699
699
700
			if ((text = Realloc(oldtext, maxlen)) == NULL) {
700
			if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
701
				SAFE_FREE(oldtext);
701
				SAFE_FREE(oldtext);
702
				errno = ENOMEM;
702
				errno = ENOMEM;
703
				return NULL;
703
				return NULL;
Lines 1334-1340 Link Here
1334
1334
1335
			maxlen += nbytes + 20 * (acl_d->count - i);
1335
			maxlen += nbytes + 20 * (acl_d->count - i);
1336
1336
1337
			if ((text = Realloc(oldtext, maxlen)) == NULL) {
1337
			if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
1338
				SAFE_FREE(oldtext);
1338
				SAFE_FREE(oldtext);
1339
				errno = ENOMEM;
1339
				errno = ENOMEM;
1340
				return NULL;
1340
				return NULL;
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/system.c (-4 / +4 lines)
Lines 674-680 Link Here
674
	if (setlen == 0)
674
	if (setlen == 0)
675
		setlen = groups_max();
675
		setlen = groups_max();
676
676
677
	if((group_list = (GID_T *)malloc(setlen * sizeof(GID_T))) == NULL) {
677
	if((group_list = SMB_MALLOC_ARRAY( GID_T, setlen )) == NULL) {
678
		DEBUG(0,("sys_getgroups: Malloc fail.\n"));
678
		DEBUG(0,("sys_getgroups: Malloc fail.\n"));
679
		return -1;
679
		return -1;
680
	}
680
	}
Lines 723-729 Link Here
723
	 * GID_T array of size setlen.
723
	 * GID_T array of size setlen.
724
	 */
724
	 */
725
725
726
	if((group_list = (GID_T *)malloc(setlen * sizeof(GID_T))) == NULL) {
726
	if((group_list = SMB_MALLOC_ARRAY( GID_T, setlen )) == NULL) {
727
		DEBUG(0,("sys_setgroups: Malloc fail.\n"));
727
		DEBUG(0,("sys_setgroups: Malloc fail.\n"));
728
		return -1;    
728
		return -1;    
729
	}
729
	}
Lines 1071-1077 Link Here
1071
	for( argcl = 1; ptr; ptr = strtok(NULL, " \t"))
1071
	for( argcl = 1; ptr; ptr = strtok(NULL, " \t"))
1072
		argcl++;
1072
		argcl++;
1073
1073
1074
	if((argl = (char **)malloc((argcl + 1) * sizeof(char *))) == NULL)
1074
	if((argl = SMB_MALLOC_ARRAY(char *, argcl + 1 )) == NULL)
1075
		return NULL;
1075
		return NULL;
1076
1076
1077
	/*
1077
	/*
Lines 1153-1159 Link Here
1153
		goto err_exit;
1153
		goto err_exit;
1154
	}
1154
	}
1155
1155
1156
	if((entry = (popen_list *)malloc(sizeof(popen_list))) == NULL)
1156
	if((entry = SMB_MALLOC_P(popen_list)) == NULL)
1157
		goto err_exit;
1157
		goto err_exit;
1158
1158
1159
	ZERO_STRUCTP(entry);
1159
	ZERO_STRUCTP(entry);
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/talloc.c (-10 / +74 lines)
Lines 54-59 Link Here
54
54
55
#include "includes.h"
55
#include "includes.h"
56
56
57
/* Max allowable allococation - 256mb - 0x10000000 */
58
#define MAX_TALLOC_SIZE (1024*1024*256)
59
57
struct talloc_chunk {
60
struct talloc_chunk {
58
	struct talloc_chunk *next;
61
	struct talloc_chunk *next;
59
	size_t size;
62
	size_t size;
Lines 121-127 Link Here
121
{
124
{
122
	TALLOC_CTX *t;
125
	TALLOC_CTX *t;
123
126
124
	t = (TALLOC_CTX *)malloc(sizeof(TALLOC_CTX));
127
	t = (TALLOC_CTX *)SMB_MALLOC(sizeof(TALLOC_CTX));
125
	if (t) {
128
	if (t) {
126
		t->list = NULL;
129
		t->list = NULL;
127
		t->total_alloc_size = 0;
130
		t->total_alloc_size = 0;
Lines 155-170 Link Here
155
158
156
159
157
/** Allocate a bit of memory from the specified pool **/
160
/** Allocate a bit of memory from the specified pool **/
161
#if defined(PARANOID_MALLOC_CHECKER)
162
void *talloc_(TALLOC_CTX *t, size_t size)
163
#else
158
void *talloc(TALLOC_CTX *t, size_t size)
164
void *talloc(TALLOC_CTX *t, size_t size)
165
#endif
159
{
166
{
160
	void *p;
167
	void *p;
161
	struct talloc_chunk *tc;
168
	struct talloc_chunk *tc;
162
169
163
	if (!t || size == 0) return NULL;
170
	if (!t || size == 0) return NULL;
164
171
165
	p = malloc(size);
172
	p = SMB_MALLOC(size);
166
	if (p) {
173
	if (p) {
167
		tc = malloc(sizeof(*tc));
174
		tc = SMB_MALLOC(sizeof(*tc));
168
		if (tc) {
175
		if (tc) {
169
			tc->ptr = p;
176
			tc->ptr = p;
170
			tc->size = size;
177
			tc->size = size;
Lines 179-186 Link Here
179
	return p;
186
	return p;
180
}
187
}
181
188
189
190
/** Allocate an array of count elements of size x */
191
#if defined(PARANOID_MALLOC_CHECKER)
192
void *talloc_array_(TALLOC_CTX *ctx, size_t el_size, unsigned int count)
193
#else
194
void *talloc_array(TALLOC_CTX *ctx, size_t el_size, unsigned int count)
195
#endif
196
{
197
        if (count >= MAX_TALLOC_SIZE/el_size) {
198
                return NULL;
199
        }
200
       return TALLOC(ctx, el_size * count);
201
}
202
182
/** A talloc version of realloc */
203
/** A talloc version of realloc */
204
#if defined(PARANOID_MALLOC_CHECKER)
205
void *talloc_realloc_(TALLOC_CTX *t, void *ptr, size_t size)
206
#else
183
void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size)
207
void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size)
208
#endif
184
{
209
{
185
	struct talloc_chunk *tc;
210
	struct talloc_chunk *tc;
186
	void *new_ptr;
211
	void *new_ptr;
Lines 191-201 Link Here
191
216
192
	/* realloc(NULL) is equavalent to malloc() */
217
	/* realloc(NULL) is equavalent to malloc() */
193
	if (ptr == NULL)
218
	if (ptr == NULL)
194
		return talloc(t, size);
219
		return TALLOC(t, size);
195
220
196
	for (tc=t->list; tc; tc=tc->next) {
221
	for (tc=t->list; tc; tc=tc->next) {
197
		if (tc->ptr == ptr) {
222
		if (tc->ptr == ptr) {
198
			new_ptr = Realloc(ptr, size);
223
			new_ptr = SMB_REALLOC(ptr, size);
199
			if (new_ptr) {
224
			if (new_ptr) {
200
				t->total_alloc_size += (size - tc->size);
225
				t->total_alloc_size += (size - tc->size);
201
				tc->size = size;
226
				tc->size = size;
Lines 207-212 Link Here
207
	return NULL;
232
	return NULL;
208
}
233
}
209
234
235
/** Re-allocate an array of count elements of size x */
236
#if defined(PARANOID_MALLOC_CHECKER)
237
void *talloc_realloc_array_(TALLOC_CTX *ctx, void *ptr, size_t el_size, unsigned int count)
238
#else
239
void *talloc_realloc_array(TALLOC_CTX *ctx, void *ptr, size_t el_size, unsigned int count)
240
#endif
241
{
242
        if (count >= MAX_TALLOC_SIZE/el_size) {
243
                return NULL;
244
        }
245
       return TALLOC_REALLOC(ctx, ptr, el_size * count);
246
}
247
210
/** Destroy all the memory allocated inside @p t, but not @p t
248
/** Destroy all the memory allocated inside @p t, but not @p t
211
 * itself. */
249
 * itself. */
212
void talloc_destroy_pool(TALLOC_CTX *t)
250
void talloc_destroy_pool(TALLOC_CTX *t)
Lines 257-265 Link Here
257
295
258
296
259
/** talloc and zero memory. */
297
/** talloc and zero memory. */
298
#if defined(PARANOID_MALLOC_CHECKER)
299
void *talloc_zero_(TALLOC_CTX *t, size_t size)
300
#else
260
void *talloc_zero(TALLOC_CTX *t, size_t size)
301
void *talloc_zero(TALLOC_CTX *t, size_t size)
302
#endif
261
{
303
{
262
	void *p = talloc(t, size);
304
	void *p = TALLOC(t, size);
263
305
264
	if (p)
306
	if (p)
265
		memset(p, '\0', size);
307
		memset(p, '\0', size);
Lines 267-276 Link Here
267
	return p;
309
	return p;
268
}
310
}
269
311
312
#if defined(PARANOID_MALLOC_CHECKER)
313
void *talloc_zero_array_(TALLOC_CTX *t, size_t el_size, unsigned int count)
314
#else
315
void *talloc_zero_array(TALLOC_CTX *t, size_t el_size, unsigned int count)
316
#endif
317
{
318
#if defined(PARANOID_MALLOC_CHECKER)
319
       void *p = talloc_array_(t, el_size, count);
320
#else
321
       void *p = talloc_array(t, el_size, count);
322
#endif
323
324
       if (p)
325
               memset(p, '\0', el_size*count);
326
327
       return p;
328
}
329
270
/** memdup with a talloc. */
330
/** memdup with a talloc. */
331
#if defined(PARANOID_MALLOC_CHECKER)
332
void *talloc_memdup_(TALLOC_CTX *t, const void *p, size_t size)
333
#else
271
void *talloc_memdup(TALLOC_CTX *t, const void *p, size_t size)
334
void *talloc_memdup(TALLOC_CTX *t, const void *p, size_t size)
335
#endif
272
{
336
{
273
	void *newp = talloc(t,size);
337
	void *newp = TALLOC(t,size);
274
338
275
	if (newp)
339
	if (newp)
276
		memcpy(newp, p, size);
340
		memcpy(newp, p, size);
Lines 282-288 Link Here
282
char *talloc_strdup(TALLOC_CTX *t, const char *p)
346
char *talloc_strdup(TALLOC_CTX *t, const char *p)
283
{
347
{
284
	if (p)
348
	if (p)
285
		return talloc_memdup(t, p, strlen(p) + 1);
349
		return TALLOC_MEMDUP(t, p, strlen(p) + 1);
286
	else
350
	else
287
		return NULL;
351
		return NULL;
288
}
352
}
Lines 312-318 Link Here
312
	VA_COPY(ap2, ap);  /* for systems were va_list is a struct */
376
	VA_COPY(ap2, ap);  /* for systems were va_list is a struct */
313
	len = vsnprintf(NULL, 0, fmt, ap2);
377
	len = vsnprintf(NULL, 0, fmt, ap2);
314
378
315
	ret = talloc(t, len+1);
379
	ret = TALLOC(t, len+1);
316
	if (ret) {
380
	if (ret) {
317
		VA_COPY(ap2, ap);
381
		VA_COPY(ap2, ap);
318
		vsnprintf(ret, len+1, fmt, ap2);
382
		vsnprintf(ret, len+1, fmt, ap2);
Lines 355-361 Link Here
355
	s_len = strlen(s);
419
	s_len = strlen(s);
356
	len = vsnprintf(NULL, 0, fmt, ap2);
420
	len = vsnprintf(NULL, 0, fmt, ap2);
357
421
358
	s = talloc_realloc(t, s, s_len + len+1);
422
	s = TALLOC_REALLOC(t, s, s_len + len+1);
359
	if (!s) return NULL;
423
	if (!s) return NULL;
360
424
361
	VA_COPY(ap2, ap);
425
	VA_COPY(ap2, ap);
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/time.c (-2 / +1 lines)
Lines 182-189 Link Here
182
    time_t low,high;
182
    time_t low,high;
183
183
184
    zone = TimeZone(t);
184
    zone = TimeZone(t);
185
    tdt = (struct dst_table *)Realloc(dst_table,
185
    tdt = SMB_REALLOC_ARRAY( dst_table, struct dst_table, i+1 );
186
					      sizeof(dst_table[0])*(i+1));
187
    if (!tdt) {
186
    if (!tdt) {
188
      DEBUG(0,("TimeZoneFaster: out of memory!\n"));
187
      DEBUG(0,("TimeZoneFaster: out of memory!\n"));
189
      SAFE_FREE(dst_table);
188
      SAFE_FREE(dst_table);
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/username.c (-1 / +1 lines)
Lines 336-342 Link Here
336
 		return False;
336
 		return False;
337
 	}
337
 	}
338
 
338
 
339
 	if ((groups = (gid_t *)malloc(sizeof(gid_t) * num_groups )) == NULL) {
339
 	if ((groups = SMB_MALLOC_ARRAY( gid_t, num_groups )) == NULL) {
340
 		DEBUG(0,("user_in_winbind_group_list: malloc fail.\n"));
340
 		DEBUG(0,("user_in_winbind_group_list: malloc fail.\n"));
341
 		goto err;
341
 		goto err;
342
 	}
342
 	}
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/util.c (-72 / +202 lines)
Lines 23-28 Link Here
23
23
24
#include "includes.h"
24
#include "includes.h"
25
25
26
/* Max allowable allococation - 256mb - 0x10000000 */
27
#define MAX_ALLOC_SIZE (1024*1024*256)
28
26
#if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
29
#if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
27
#ifdef WITH_NISPLUS_HOME
30
#ifdef WITH_NISPLUS_HOME
28
#ifdef BROKEN_NISPLUS_INCLUDE_FILES
31
#ifdef BROKEN_NISPLUS_INCLUDE_FILES
Lines 159-165 Link Here
159
	while ((p = Atoic(p, &val, ":,")) != NULL && (*p) != ':') {
162
	while ((p = Atoic(p, &val, ":,")) != NULL && (*p) != ':') {
160
		uint32 *tn;
163
		uint32 *tn;
161
164
162
		tn = Realloc((*num), ((*count)+1) * sizeof(uint32));
165
		tn = SMB_REALLOC_ARRAY( *num, uint32, (*count)+1 );
163
		if (tn == NULL)
166
		if (tn == NULL)
164
		{
167
		{
165
			SAFE_FREE(*num);
168
			SAFE_FREE(*num);
Lines 210-227 Link Here
210
213
211
BOOL directory_exist(char *dname,SMB_STRUCT_STAT *st)
214
BOOL directory_exist(char *dname,SMB_STRUCT_STAT *st)
212
{
215
{
213
  SMB_STRUCT_STAT st2;
216
	SMB_STRUCT_STAT st2;
214
  BOOL ret;
217
	BOOL ret;
215
218
216
  if (!st) st = &st2;
219
	if (!st)
220
	    st = &st2;
217
221
218
  if (sys_stat(dname,st) != 0) 
222
	if (sys_stat(dname,st) != 0) 
219
    return(False);
223
	    return(False);
220
224
221
  ret = S_ISDIR(st->st_mode);
225
	ret = S_ISDIR(st->st_mode);
222
  if(!ret)
226
	if(!ret)
223
    errno = ENOTDIR;
227
	    errno = ENOTDIR;
224
  return ret;
228
	return ret;
225
}
229
}
226
230
227
/*******************************************************************
231
/*******************************************************************
Lines 525-531 Link Here
525
	size_t num_to_read_thistime;
529
	size_t num_to_read_thistime;
526
	size_t num_written = 0;
530
	size_t num_written = 0;
527
531
528
	if ((buf = malloc(TRANSFER_BUF_SIZE)) == NULL)
532
	if ((buf = SMB_MALLOC(TRANSFER_BUF_SIZE)) == NULL)
529
		return -1;
533
		return -1;
530
534
531
	while (total < n) {
535
	while (total < n) {
Lines 650-660 Link Here
650
	return(False);
654
	return(False);
651
}
655
}
652
656
657
#if defined(PARANOID_MALLOC_CHECKER)
658
659
/****************************************************************************
660
 Internal malloc wrapper. Externally visible.
661
****************************************************************************/
662
663
void *malloc_(size_t size)
664
{
665
	if ( size > MAX_ALLOC_SIZE )
666
		return NULL;
667
#undef malloc
668
       return malloc(size);
669
#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY
670
}
671
672
/****************************************************************************
673
 Internal calloc wrapper. Not externally visible.
674
****************************************************************************/
675
676
static void *calloc_(size_t count, size_t size)
677
{
678
#undef calloc
679
       return calloc(count, size);
680
#define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY
681
}
682
683
/****************************************************************************
684
 Internal realloc wrapper. Not externally visible.
685
****************************************************************************/
686
687
static void *realloc_(void *ptr, size_t size)
688
{
689
#undef realloc
690
       return realloc(ptr, size);
691
#define realloc(p,s) __ERROR_DONT_USE_RELLOC_DIRECTLY
692
}
693
694
#endif /* PARANOID_MALLOC_CHECKER */
695
696
/****************************************************************************
697
 Type-safe malloc.
698
****************************************************************************/
699
700
void *malloc_array(size_t el_size, unsigned int count)
701
{
702
       if (count >= MAX_ALLOC_SIZE/el_size) {
703
	       return NULL;
704
       }
705
706
#if defined(PARANOID_MALLOC_CHECKER)
707
       return malloc_(el_size*count);
708
#else
709
       return malloc(el_size*count);
710
#endif
711
}
712
713
/****************************************************************************
714
 Type-safe calloc.
715
****************************************************************************/
716
717
void *calloc_array(size_t size, size_t nmemb)
718
{
719
       if (nmemb >= MAX_ALLOC_SIZE/size) {
720
	       return NULL;
721
       }
722
#if defined(PARANOID_MALLOC_CHECKER)
723
       return calloc_(nmemb, size);
724
#else
725
       return calloc(nmemb, size);
726
#endif
727
}
728
653
/****************************************************************************
729
/****************************************************************************
654
 Expand a pointer to be a particular size.
730
 Expand a pointer to be a particular size.
655
****************************************************************************/
731
****************************************************************************/
656
732
657
void *Realloc(void *p,size_t size)
733
void *smb_realloc(void *p,size_t size)
658
{
734
{
659
	void *ret=NULL;
735
	void *ret=NULL;
660
736
Lines 663-673 Link Here
663
		DEBUG(5,("Realloc asked for 0 bytes\n"));
739
		DEBUG(5,("Realloc asked for 0 bytes\n"));
664
		return NULL;
740
		return NULL;
665
	}
741
	}
666
742
	if ( size >= MAX_ALLOC_SIZE ) {
743
		SAFE_FREE(p);
744
		DEBUG(5,("Realloc overflow\n"));
745
		return NULL;
746
	}
747
#if defined(PARANOID_MALLOC_CHECKER)
748
       if (!p)
749
	       ret = (void *)malloc_(size);
750
       else
751
	       ret = (void *)realloc_(p,size);
752
#else
667
	if (!p)
753
	if (!p)
668
		ret = (void *)malloc(size);
754
		ret = (void *)malloc(size);
669
	else
755
	else
670
		ret = (void *)realloc(p,size);
756
		ret = (void *)realloc(p,size);
757
#endif
671
758
672
	if (!ret)
759
	if (!ret)
673
		DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
760
		DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
Lines 676-681 Link Here
676
}
763
}
677
764
678
/****************************************************************************
765
/****************************************************************************
766
 Type-safe realloc.
767
+****************************************************************************/
768
769
void *realloc_array(void *p,size_t el_size, unsigned int count)
770
{
771
       if (count >= MAX_ALLOC_SIZE/el_size) {
772
	    return NULL;
773
	}
774
       return SMB_REALLOC(p,el_size*count);
775
}
776
									      
777
/****************************************************************************
679
 Free memory, checks for NULL.
778
 Free memory, checks for NULL.
680
use directly SAFE_FREE()
779
use directly SAFE_FREE()
681
exist only because we need to pass a function pointer somewhere --SSS
780
exist only because we need to pass a function pointer somewhere --SSS
Lines 886-907 Link Here
886
    {
985
    {
887
       if (result->status != NIS_SUCCESS)
986
       if (result->status != NIS_SUCCESS)
888
      {
987
      {
889
        DEBUG(3, ("NIS+ query failed: %s\n", nis_sperrno(result->status)));
988
	DEBUG(3, ("NIS+ query failed: %s\n", nis_sperrno(result->status)));
890
        fstrcpy(last_key, ""); pstrcpy(last_value, "");
989
	fstrcpy(last_key, ""); pstrcpy(last_value, "");
891
      }
990
      }
892
      else
991
      else
893
      {
992
      {
894
        object = result->objects.objects_val;
993
	object = result->objects.objects_val;
895
        if (object->zo_data.zo_type == ENTRY_OBJ)
994
	if (object->zo_data.zo_type == ENTRY_OBJ)
896
        {
995
	{
897
           entry = &object->zo_data.objdata_u.en_data;
996
	   entry = &object->zo_data.objdata_u.en_data;
898
           DEBUG(5, ("NIS+ entry type: %s\n", entry->en_type));
997
	   DEBUG(5, ("NIS+ entry type: %s\n", entry->en_type));
899
           DEBUG(3, ("NIS+ result: %s\n", entry->en_cols.en_cols_val[1].ec_value.ec_value_val));
998
	   DEBUG(3, ("NIS+ result: %s\n", entry->en_cols.en_cols_val[1].ec_value.ec_value_val));
900
 
999
 
901
           pstrcpy(last_value, entry->en_cols.en_cols_val[1].ec_value.ec_value_val);
1000
	   pstrcpy(last_value, entry->en_cols.en_cols_val[1].ec_value.ec_value_val);
902
           pstring_sub(last_value, "&", user_name);
1001
	   pstring_sub(last_value, "&", user_name);
903
           fstrcpy(last_key, user_name);
1002
	   fstrcpy(last_key, user_name);
904
        }
1003
	}
905
      }
1004
      }
906
    }
1005
    }
907
    nis_freeresult(result);
1006
    nis_freeresult(result);
Lines 918-924 Link Here
918
  static fstring last_key = "";
1017
  static fstring last_key = "";
919
  static pstring last_value = "";
1018
  static pstring last_value = "";
920
1019
921
  int nis_error;        /* returned by yp all functions */
1020
  int nis_error;	/* returned by yp all functions */
922
  char *nis_result;     /* yp_match inits this */
1021
  char *nis_result;     /* yp_match inits this */
923
  int nis_result_len;  /* and set this */
1022
  int nis_result_len;  /* and set this */
924
  char *nis_domain;     /* yp_get_default_domain inits this */
1023
  char *nis_domain;     /* yp_get_default_domain inits this */
Lines 939-953 Link Here
939
  } else {
1038
  } else {
940
1039
941
    if ((nis_error = yp_match(nis_domain, nis_map,
1040
    if ((nis_error = yp_match(nis_domain, nis_map,
942
                              user_name, strlen(user_name),
1041
			      user_name, strlen(user_name),
943
                              &nis_result, &nis_result_len)) == 0) {
1042
			      &nis_result, &nis_result_len)) == 0) {
944
       if (!nis_error && nis_result_len >= sizeof(pstring)) {
1043
       if (!nis_error && nis_result_len >= sizeof(pstring)) {
945
               nis_result_len = sizeof(pstring)-1;
1044
	       nis_result_len = sizeof(pstring)-1;
946
       }
1045
       }
947
       fstrcpy(last_key, user_name);
1046
       fstrcpy(last_key, user_name);
948
       strncpy(last_value, nis_result, nis_result_len);
1047
       strncpy(last_value, nis_result, nis_result_len);
949
       last_value[nis_result_len] = '\0';
1048
       last_value[nis_result_len] = '\0';
950
        strip_mount_options(&last_value);
1049
	strip_mount_options(&last_value);
951
1050
952
    } else if(nis_error == YPERR_KEY) {
1051
    } else if(nis_error == YPERR_KEY) {
953
1052
Lines 955-965 Link Here
955
       use default information for server, and home directory */
1054
       use default information for server, and home directory */
956
       last_value[0] = 0;
1055
       last_value[0] = 0;
957
       DEBUG(3, ("YP Key not found:  while looking up \"%s\" in map \"%s\"\n", 
1056
       DEBUG(3, ("YP Key not found:  while looking up \"%s\" in map \"%s\"\n", 
958
                user_name, nis_map));
1057
		user_name, nis_map));
959
       DEBUG(3, ("using defaults for server and home directory\n"));
1058
       DEBUG(3, ("using defaults for server and home directory\n"));
960
    } else {
1059
    } else {
961
       DEBUG(3, ("YP Error: \"%s\" while looking up \"%s\" in map \"%s\"\n", 
1060
       DEBUG(3, ("YP Error: \"%s\" while looking up \"%s\" in map \"%s\"\n", 
962
               yperr_string(nis_error), user_name, nis_map));
1061
	       yperr_string(nis_error), user_name, nis_map));
963
    }
1062
    }
964
  }
1063
  }
965
1064
Lines 981-987 Link Here
981
  nmask = ntohl(mask.s_addr);
1080
  nmask = ntohl(mask.s_addr);
982
  net1  = ntohl(ip1.s_addr);
1081
  net1  = ntohl(ip1.s_addr);
983
  net2  = ntohl(ip2.s_addr);
1082
  net2  = ntohl(ip2.s_addr);
984
            
1083
	    
985
  return((net1 & nmask) == (net2 & nmask));
1084
  return((net1 & nmask) == (net2 & nmask));
986
}
1085
}
987
1086
Lines 1162-1179 Link Here
1162
    {
1261
    {
1163
      if (mask_match(last_component, namelist->name, case_sensitive))
1262
      if (mask_match(last_component, namelist->name, case_sensitive))
1164
      {
1263
      {
1165
         DEBUG(8,("is_in_path: mask match succeeded\n"));
1264
	 DEBUG(8,("is_in_path: mask match succeeded\n"));
1166
         return True;
1265
	 return True;
1167
      }
1266
      }
1168
    }
1267
    }
1169
    else
1268
    else
1170
    {
1269
    {
1171
      if((case_sensitive && (strcmp(last_component, namelist->name) == 0))||
1270
      if((case_sensitive && (strcmp(last_component, namelist->name) == 0))||
1172
       (!case_sensitive && (StrCaseCmp(last_component, namelist->name) == 0)))
1271
       (!case_sensitive && (StrCaseCmp(last_component, namelist->name) == 0)))
1173
        {
1272
	{
1174
         DEBUG(8,("is_in_path: match succeeded\n"));
1273
	 DEBUG(8,("is_in_path: match succeeded\n"));
1175
         return True;
1274
	 return True;
1176
        }
1275
	}
1177
    }
1276
    }
1178
  }
1277
  }
1179
  DEBUG(8,("is_in_path: match not found\n"));
1278
  DEBUG(8,("is_in_path: match not found\n"));
Lines 1213-1229 Link Here
1213
  while(*nameptr) 
1312
  while(*nameptr) 
1214
    {
1313
    {
1215
      if ( *nameptr == '/' ) 
1314
      if ( *nameptr == '/' ) 
1216
        {
1315
	{
1217
          /* cope with multiple (useless) /s) */
1316
	  /* cope with multiple (useless) /s) */
1218
          nameptr++;
1317
	  nameptr++;
1219
          continue;
1318
	  continue;
1220
        }
1319
	}
1221
      /* find the next / */
1320
      /* find the next / */
1222
      name_end = strchr(nameptr, '/');
1321
      name_end = strchr(nameptr, '/');
1223
1322
1224
      /* oops - the last check for a / didn't find one. */
1323
      /* oops - the last check for a / didn't find one. */
1225
      if (name_end == NULL)
1324
      if (name_end == NULL)
1226
        break;
1325
	break;
1227
1326
1228
      /* next segment please */
1327
      /* next segment please */
1229
      nameptr = name_end + 1;
1328
      nameptr = name_end + 1;
Lines 1233-1271 Link Here
1233
  if(num_entries == 0)
1332
  if(num_entries == 0)
1234
    return;
1333
    return;
1235
1334
1236
  if(( (*ppname_array) = (name_compare_entry *)malloc( 
1335
  if(( (*ppname_array) = SMB_MALLOC_ARRAY( name_compare_entry, num_entries + 1)) == NULL)
1237
           (num_entries + 1) * sizeof(name_compare_entry))) == NULL)
1336
	{
1238
        {
1239
    DEBUG(0,("set_namearray: malloc fail\n"));
1337
    DEBUG(0,("set_namearray: malloc fail\n"));
1240
    return;
1338
    return;
1241
        }
1339
	}
1242
1340
1243
  /* Now copy out the names */
1341
  /* Now copy out the names */
1244
  nameptr = namelist;
1342
  nameptr = namelist;
1245
  i = 0;
1343
  i = 0;
1246
  while(*nameptr)
1344
  while(*nameptr)
1247
             {
1345
	     {
1248
      if ( *nameptr == '/' ) 
1346
      if ( *nameptr == '/' ) 
1249
      {
1347
      {
1250
          /* cope with multiple (useless) /s) */
1348
	  /* cope with multiple (useless) /s) */
1251
          nameptr++;
1349
	  nameptr++;
1252
          continue;
1350
	  continue;
1253
      }
1351
      }
1254
      /* find the next / */
1352
      /* find the next / */
1255
      if ((name_end = strchr(nameptr, '/')) != NULL) 
1353
      if ((name_end = strchr(nameptr, '/')) != NULL) 
1256
      {
1354
      {
1257
          *name_end = 0;
1355
	  *name_end = 0;
1258
         }
1356
	 }
1259
1357
1260
      /* oops - the last check for a / didn't find one. */
1358
      /* oops - the last check for a / didn't find one. */
1261
      if(name_end == NULL) 
1359
      if(name_end == NULL) 
1262
        break;
1360
	break;
1263
1361
1264
      (*ppname_array)[i].is_wild = ms_has_wild(nameptr);
1362
      (*ppname_array)[i].is_wild = ms_has_wild(nameptr);
1265
      if(((*ppname_array)[i].name = strdup(nameptr)) == NULL)
1363
      if(((*ppname_array)[i].name = SMB_STRDUP(nameptr)) == NULL)
1266
      {
1364
      {
1267
        DEBUG(0,("set_namearray: malloc fail (1)\n"));
1365
	DEBUG(0,("set_namearray: malloc fail (1)\n"));
1268
        return;
1366
	return;
1269
      }
1367
      }
1270
1368
1271
      /* next segment please */
1369
      /* next segment please */
Lines 1322-1330 Link Here
1322
  if (op == SMB_F_GETLK)
1420
  if (op == SMB_F_GETLK)
1323
  {
1421
  {
1324
    if ((ret != -1) &&
1422
    if ((ret != -1) &&
1325
        (lock.l_type != F_UNLCK) && 
1423
	(lock.l_type != F_UNLCK) && 
1326
        (lock.l_pid != 0) && 
1424
	(lock.l_pid != 0) && 
1327
        (lock.l_pid != sys_getpid()))
1425
	(lock.l_pid != sys_getpid()))
1328
    {
1426
    {
1329
      DEBUG(3,("fcntl_lock: fd %d is locked by pid %d\n",fd,(int)lock.l_pid));
1427
      DEBUG(3,("fcntl_lock: fd %d is locked by pid %d\n",fd,(int)lock.l_pid));
1330
      return(True);
1428
      return(True);
Lines 1338-1344 Link Here
1338
  if (ret == -1)
1436
  if (ret == -1)
1339
  {
1437
  {
1340
    DEBUG(3,("fcntl_lock: lock failed at offset %.0f count %.0f op %d type %d (%s)\n",
1438
    DEBUG(3,("fcntl_lock: lock failed at offset %.0f count %.0f op %d type %d (%s)\n",
1341
          (double)offset,(double)count,op,type,strerror(errno)));
1439
	  (double)offset,(double)count,op,type,strerror(errno)));
1342
    return(False);
1440
    return(False);
1343
  }
1441
  }
1344
1442
Lines 1577-1583 Link Here
1577
 * Provide a checksum on a string
1675
 * Provide a checksum on a string
1578
 *
1676
 *
1579
 *  Input:  s - the null-terminated character string for which the checksum
1677
 *  Input:  s - the null-terminated character string for which the checksum
1580
 *              will be calculated.
1678
 *	      will be calculated.
1581
 *
1679
 *
1582
 *  Output: The checksum value calculated for s.
1680
 *  Output: The checksum value calculated for s.
1583
 *
1681
 *
Lines 1757-1769 Link Here
1757
 malloc that aborts with smb_panic on fail or zero size.
1855
 malloc that aborts with smb_panic on fail or zero size.
1758
 *****************************************************************/  
1856
 *****************************************************************/  
1759
1857
1760
void *smb_xmalloc(size_t size)
1858
void *smb_xmalloc_array(size_t size, unsigned int count)
1761
{
1859
{
1762
	void *p;
1860
	void *p;
1763
	if (size == 0)
1861
	if (size == 0)
1764
		smb_panic("smb_xmalloc: called with zero size.\n");
1862
	       smb_panic("smb_xmalloc_array: called with zero size.\n");
1765
	if ((p = malloc(size)) == NULL)
1863
	if (count >= MAX_ALLOC_SIZE/size) {
1766
		smb_panic("smb_xmalloc: malloc fail.\n");
1864
		smb_panic("smb_xmalloc: alloc size too large.\n");
1865
	}
1866
	if ((p = SMB_MALLOC(size*count)) == NULL) {
1867
	       DEBUG(0, ("smb_xmalloc_array failed to allocate %lu * %lu bytes\n",
1868
		       (unsigned long)size, (unsigned long)count));
1869
	       smb_panic("smb_xmalloc_array: malloc fail.\n");
1870
	}
1767
	return p;
1871
	return p;
1768
}
1872
}
1769
1873
Lines 1773-1779 Link Here
1773
void *smb_xmemdup(const void *p, size_t size)
1877
void *smb_xmemdup(const void *p, size_t size)
1774
{
1878
{
1775
	void *p2;
1879
	void *p2;
1776
	p2 = smb_xmalloc(size);
1880
	p2 = SMB_XMALLOC_ARRAY(unsigned char, size);
1777
	memcpy(p2, p, size);
1881
	memcpy(p2, p, size);
1778
	return p2;
1882
	return p2;
1779
}
1883
}
Lines 1783-1794 Link Here
1783
**/
1887
**/
1784
char *smb_xstrdup(const char *s)
1888
char *smb_xstrdup(const char *s)
1785
{
1889
{
1890
#if defined(PARANOID_MALLOC_CHECKER) && defined(strdup)
1891
#undef strdup
1892
#endif
1786
	char *s1 = strdup(s);
1893
	char *s1 = strdup(s);
1894
#if defined(PARANOID_MALLOC_CHECKER)
1895
#define strdup(s) __ERROR_DONT_USE_STRDUP_DIRECTLY
1896
#endif
1787
	if (!s1)
1897
	if (!s1)
1788
		smb_panic("smb_xstrdup: malloc fail\n");
1898
		smb_panic("smb_xstrdup: malloc fail\n");
1789
	return s1;
1899
	return s1;
1790
}
1900
}
1791
1901
1902
/**
1903
 strndup that aborts on malloc fail.
1904
 **/
1905
1906
char *smb_xstrndup(const char *s, size_t n)
1907
{
1908
#if defined(PARANOID_MALLOC_CHECKER)
1909
#ifdef strndup
1910
#undef strndup
1911
#endif
1912
#endif
1913
	char *s1 = strndup(s, n);
1914
#if defined(PARANOID_MALLOC_CHECKER)
1915
#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY
1916
#endif
1917
	if (!s1)
1918
		smb_panic("smb_xstrndup: malloc fail\n");
1919
	return s1;
1920
}
1921
1792
/*
1922
/*
1793
  vasprintf that aborts on malloc fail
1923
  vasprintf that aborts on malloc fail
1794
*/
1924
*/
Lines 1813-1819 Link Here
1813
{
1943
{
1814
	void *p2;
1944
	void *p2;
1815
	if (size == 0) return NULL;
1945
	if (size == 0) return NULL;
1816
	p2 = malloc(size);
1946
	p2 = SMB_MALLOC(size);
1817
	if (!p2) return NULL;
1947
	if (!p2) return NULL;
1818
	memcpy(p2, p, size);
1948
	memcpy(p2, p, size);
1819
	return p2;
1949
	return p2;
Lines 2095-2101 Link Here
2095
	if (p) {
2225
	if (p) {
2096
		ret.data = smb_xmemdup(p, length);
2226
		ret.data = smb_xmemdup(p, length);
2097
	} else {
2227
	} else {
2098
		ret.data = smb_xmalloc(length);
2228
		ret.data = SMB_XMALLOC_ARRAY(char, length);
2099
	}
2229
	}
2100
	ret.length = length;
2230
	ret.length = length;
2101
	ret.free = free_data_blob;
2231
	ret.free = free_data_blob;
Lines 2115-2121 Link Here
2115
		return ret;
2245
		return ret;
2116
	}
2246
	}
2117
2247
2118
	ret.data = talloc_memdup(mem_ctx, p, length);
2248
	ret.data = TALLOC_MEMDUP(mem_ctx, p, length);
2119
	if (ret.data == NULL)
2249
	if (ret.data == NULL)
2120
		smb_panic("data_blob_talloc: talloc_memdup failed.\n");
2250
		smb_panic("data_blob_talloc: talloc_memdup failed.\n");
2121
2251
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/util_file.c (-5 / +13 lines)
Lines 288-294 Link Here
288
      char *t;
288
      char *t;
289
289
290
      maxlen = MIN(maxlen,8);
290
      maxlen = MIN(maxlen,8);
291
      t = (char *)Realloc(s,maxlen);
291
      t = (char *)SMB_REALLOC(s,maxlen);
292
      if (!t) {
292
      if (!t) {
293
        DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
293
        DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
294
        SAFE_FREE(s);
294
        SAFE_FREE(s);
Lines 337-343 Link Here
337
        char *t;
337
        char *t;
338
338
339
        maxlen *= 2;
339
        maxlen *= 2;
340
        t = (char *)Realloc(s,maxlen);
340
        t = (char *)SMB_REALLOC(s,maxlen);
341
        if (!t) {
341
        if (!t) {
342
          DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
342
          DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
343
          SAFE_FREE(s);
343
          SAFE_FREE(s);
Lines 367-373 Link Here
367
	total = 0;
367
	total = 0;
368
368
369
	while ((n = read(fd, buf, sizeof(buf))) > 0) {
369
	while ((n = read(fd, buf, sizeof(buf))) > 0) {
370
		tp = Realloc(p, total + n + 1);
370
		if(total >= INT_MAX-n) {
371
			DEBUG(0,("file_pload: integer overflow detected.\n"));
372
			close(fd);
373
			SAFE_FREE(p);
374
			return NULL;
375
		}
376
		tp = SMB_REALLOC(p, total + n + 1);
371
		if (!tp) {
377
		if (!tp) {
372
			DEBUG(0,("file_pload: failed to exand buffer!\n"));
378
			DEBUG(0,("file_pload: failed to exand buffer!\n"));
373
			close(fd);
379
			close(fd);
Lines 398-404 Link Here
398
404
399
	if (sys_fstat(fd, &sbuf) != 0) return NULL;
405
	if (sys_fstat(fd, &sbuf) != 0) return NULL;
400
406
401
	p = (char *)malloc(sbuf.st_size+1);
407
	if(sbuf.st_size >= INT_MAX)
408
		return NULL;
409
	p = (char *)SMB_MALLOC(sbuf.st_size+1);
402
	if (!p) return NULL;
410
	if (!p) return NULL;
403
411
404
	if (read(fd, p, sbuf.st_size) != sbuf.st_size) {
412
	if (read(fd, p, sbuf.st_size) != sbuf.st_size) {
Lines 447-453 Link Here
447
		if (s[0] == '\n') i++;
455
		if (s[0] == '\n') i++;
448
	}
456
	}
449
457
450
	ret = (char **)malloc(sizeof(ret[0])*(i+2));
458
	ret = SMB_MALLOC_ARRAY( char *, i+2 );
451
	if (!ret) {
459
	if (!ret) {
452
		SAFE_FREE(p);
460
		SAFE_FREE(p);
453
		return NULL;
461
		return NULL;
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/util_getent.c (-15 / +15 lines)
Lines 55-61 Link Here
55
	struct sys_grent *gent;
55
	struct sys_grent *gent;
56
	struct group *grp;
56
	struct group *grp;
57
	
57
	
58
	gent = (struct sys_grent *) malloc(sizeof(struct sys_grent));
58
	gent = SMB_MALLOC_P(struct sys_grent);
59
	if (gent == NULL) {
59
	if (gent == NULL) {
60
		DEBUG (0, ("Out of memory in getgrent_list!\n"));
60
		DEBUG (0, ("Out of memory in getgrent_list!\n"));
61
		return NULL;
61
		return NULL;
Lines 75-85 Link Here
75
		int i,num;
75
		int i,num;
76
		
76
		
77
		if (grp->gr_name) {
77
		if (grp->gr_name) {
78
			if ((gent->gr_name = strdup(grp->gr_name)) == NULL)
78
			if ((gent->gr_name = SMB_STRDUP(grp->gr_name)) == NULL)
79
				goto err;
79
				goto err;
80
		}
80
		}
81
		if (grp->gr_passwd) {
81
		if (grp->gr_passwd) {
82
			if ((gent->gr_passwd = strdup(grp->gr_passwd)) == NULL)
82
			if ((gent->gr_passwd = SMB_STRDUP(grp->gr_passwd)) == NULL)
83
				goto err;
83
				goto err;
84
		}
84
		}
85
		gent->gr_gid = grp->gr_gid;
85
		gent->gr_gid = grp->gr_gid;
Lines 89-108 Link Here
89
			;
89
			;
90
		
90
		
91
		/* alloc space for gr_mem string pointers */
91
		/* alloc space for gr_mem string pointers */
92
		if ((gent->gr_mem = (char **) malloc((num+1) * sizeof(char *))) == NULL)
92
		if ((gent->gr_mem = SMB_MALLOC_ARRAY( char *, num+1 )) == NULL)
93
			goto err;
93
			goto err;
94
94
95
		memset(gent->gr_mem, '\0', (num+1) * sizeof(char *));
95
		memset(gent->gr_mem, '\0', (num+1) * sizeof(char *));
96
96
97
		for (i=0; i < num; i++) {
97
		for (i=0; i < num; i++) {
98
			if ((gent->gr_mem[i] = strdup(grp->gr_mem[i])) == NULL)
98
			if ((gent->gr_mem[i] = SMB_STRDUP(grp->gr_mem[i])) == NULL)
99
				goto err;
99
				goto err;
100
		}
100
		}
101
		gent->gr_mem[num] = NULL;
101
		gent->gr_mem[num] = NULL;
102
		
102
		
103
		grp = getgrent();
103
		grp = getgrent();
104
		if (grp) {
104
		if (grp) {
105
			gent->next = (struct sys_grent *) malloc(sizeof(struct sys_grent));
105
			gent->next = SMB_MALLOC_P(struct sys_grent);
106
			if (gent->next == NULL)
106
			if (gent->next == NULL)
107
				goto err;
107
				goto err;
108
			gent = gent->next;
108
			gent = gent->next;
Lines 156-162 Link Here
156
	struct sys_pwent *pent;
156
	struct sys_pwent *pent;
157
	struct passwd *pwd;
157
	struct passwd *pwd;
158
	
158
	
159
	pent = (struct sys_pwent *) malloc(sizeof(struct sys_pwent));
159
	pent = SMB_MALLOC_P(struct sys_pwent);
160
	if (pent == NULL) {
160
	if (pent == NULL) {
161
		DEBUG (0, ("Out of memory in getpwent_list!\n"));
161
		DEBUG (0, ("Out of memory in getpwent_list!\n"));
162
		return NULL;
162
		return NULL;
Lines 168-198 Link Here
168
	while (pwd != NULL) {
168
	while (pwd != NULL) {
169
		memset(pent, '\0', sizeof(struct sys_pwent));
169
		memset(pent, '\0', sizeof(struct sys_pwent));
170
		if (pwd->pw_name) {
170
		if (pwd->pw_name) {
171
			if ((pent->pw_name = strdup(pwd->pw_name)) == NULL)
171
			if ((pent->pw_name = SMB_STRDUP(pwd->pw_name)) == NULL)
172
				goto err;
172
				goto err;
173
		}
173
		}
174
		if (pwd->pw_passwd) {
174
		if (pwd->pw_passwd) {
175
			if ((pent->pw_passwd = strdup(pwd->pw_passwd)) == NULL)
175
			if ((pent->pw_passwd = SMB_STRDUP(pwd->pw_passwd)) == NULL)
176
				goto err;
176
				goto err;
177
		}
177
		}
178
		pent->pw_uid = pwd->pw_uid;
178
		pent->pw_uid = pwd->pw_uid;
179
		pent->pw_gid = pwd->pw_gid;
179
		pent->pw_gid = pwd->pw_gid;
180
		if (pwd->pw_gecos) {
180
		if (pwd->pw_gecos) {
181
			if ((pent->pw_name = strdup(pwd->pw_gecos)) == NULL)
181
			if ((pent->pw_name = SMB_STRDUP(pwd->pw_gecos)) == NULL)
182
				goto err;
182
				goto err;
183
		}
183
		}
184
		if (pwd->pw_dir) {
184
		if (pwd->pw_dir) {
185
			if ((pent->pw_name = strdup(pwd->pw_dir)) == NULL)
185
			if ((pent->pw_name = SMB_STRDUP(pwd->pw_dir)) == NULL)
186
				goto err;
186
				goto err;
187
		}
187
		}
188
		if (pwd->pw_shell) {
188
		if (pwd->pw_shell) {
189
			if ((pent->pw_name = strdup(pwd->pw_shell)) == NULL)
189
			if ((pent->pw_name = SMB_STRDUP(pwd->pw_shell)) == NULL)
190
				goto err;
190
				goto err;
191
		}
191
		}
192
192
193
		pwd = getpwent();
193
		pwd = getpwent();
194
		if (pwd) {
194
		if (pwd) {
195
			pent->next = (struct sys_pwent *) malloc(sizeof(struct sys_pwent));
195
			pent->next = SMB_MALLOC_P(struct sys_pwent);
196
			if (pent->next == NULL)
196
			if (pent->next == NULL)
197
				goto err;
197
				goto err;
198
			pent = pent->next;
198
			pent = pent->next;
Lines 245-256 Link Here
245
		;
245
		;
246
246
247
	for (i = 0; i < num_users; i++) {
247
	for (i = 0; i < num_users; i++) {
248
		struct sys_userlist *entry = (struct sys_userlist *)malloc(sizeof(*entry));
248
		struct sys_userlist *entry = SMB_MALLOC_P(struct sys_userlist);
249
		if (entry == NULL) {
249
		if (entry == NULL) {
250
			free_userlist(list_head);
250
			free_userlist(list_head);
251
			return NULL;
251
			return NULL;
252
		}
252
		}
253
		entry->unix_name = strdup(grp->gr_mem[i]);
253
		entry->unix_name = SMB_STRDUP(grp->gr_mem[i]);
254
		if (entry->unix_name == NULL) {
254
		if (entry->unix_name == NULL) {
255
			SAFE_FREE(entry);
255
			SAFE_FREE(entry);
256
			free_userlist(list_head);
256
			free_userlist(list_head);
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/util_seaccess.c (-1 / +1 lines)
Lines 352-358 Link Here
352
352
353
	the_acl = parent_ctr->dacl;
353
	the_acl = parent_ctr->dacl;
354
354
355
	if (!(new_ace_list = talloc(ctx, sizeof(SEC_ACE) * the_acl->num_aces))) 
355
	if (!(new_ace_list = TALLOC(ctx, sizeof(SEC_ACE) * the_acl->num_aces))) 
356
		return NULL;
356
		return NULL;
357
357
358
	for (i = 0; the_acl && i < the_acl->num_aces; i++) {
358
	for (i = 0; the_acl && i < the_acl->num_aces; i++) {
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/util_sid.c (-4 / +4 lines)
Lines 394-400 Link Here
394
394
395
  memset((char *)sidout, '\0', sizeof(DOM_SID));
395
  memset((char *)sidout, '\0', sizeof(DOM_SID));
396
396
397
  p = q = strdup(sidstr + 2);
397
  p = q = SMB_STRDUP(sidstr + 2);
398
  if (p == NULL) {
398
  if (p == NULL) {
399
    DEBUG(0, ("string_to_sid: out of memory!\n"));
399
    DEBUG(0, ("string_to_sid: out of memory!\n"));
400
    return False;
400
    return False;
Lines 511-517 Link Here
511
  if(!src)
511
  if(!src)
512
    return NULL;
512
    return NULL;
513
513
514
  if((dst = malloc(sizeof(DOM_SID))) != NULL) {
514
  if((dst = SMB_MALLOC_P(DOM_SID)) != NULL) {
515
	memset(dst, '\0', sizeof(DOM_SID));
515
	memset(dst, '\0', sizeof(DOM_SID));
516
	sid_copy( dst, src);
516
	sid_copy( dst, src);
517
  }
517
  }
Lines 715-722 Link Here
715
char *sid_binstring(DOM_SID *sid)
715
char *sid_binstring(DOM_SID *sid)
716
{
716
{
717
	char *buf, *s;
717
	char *buf, *s;
718
	int len = sid_size(sid);
718
	size_t len = sid_size(sid);
719
	buf = malloc(len);
719
	buf = SMB_MALLOC(len);
720
	if (!buf) return NULL;
720
	if (!buf) return NULL;
721
	sid_linearize(buf, len, sid);
721
	sid_linearize(buf, len, sid);
722
	s = binary_string(buf, len);
722
	s = binary_string(buf, len);
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/util_str.c (-7 / +10 lines)
Lines 103-109 Link Here
103
  *ctok=ictok;
103
  *ctok=ictok;
104
  s=last_ptr;
104
  s=last_ptr;
105
105
106
  if (!(ret=iret=malloc(ictok*sizeof(char *)))) return NULL;
106
  if (!(ret=iret=SMB_MALLOC_ARRAY( char *, ictok ))) return NULL;
107
  
107
  
108
  while(ictok--) {    
108
  while(ictok--) {    
109
    *iret++=s;
109
    *iret++=s;
Lines 977-983 Link Here
977
	if (buflen >= (2*maxlength))
977
	if (buflen >= (2*maxlength))
978
		buflen = 2*(maxlength - 1);
978
		buflen = 2*(maxlength - 1);
979
979
980
	str_ucs = (smb_ucs2_t*)malloc(buflen);
980
	str_ucs = (smb_ucs2_t*)SMB_MALLOC(buflen);
981
	if(!str_ucs) {
981
	if(!str_ucs) {
982
		*dest=0;
982
		*dest=0;
983
		return dest;
983
		return dest;
Lines 990-996 Link Here
990
990
991
	/* Get UCS2 version of other_safe_chars string*/
991
	/* Get UCS2 version of other_safe_chars string*/
992
	buflen=2*strlen(other_safe_chars)+2;
992
	buflen=2*strlen(other_safe_chars)+2;
993
	other_ucs = (smb_ucs2_t*)malloc(buflen);
993
	other_ucs = (smb_ucs2_t*)SMB_MALLOC(buflen);
994
	if(!other_ucs) {
994
	if(!other_ucs) {
995
		*dest=0;
995
		*dest=0;
996
		SAFE_FREE(str_ucs);
996
		SAFE_FREE(str_ucs);
Lines 1144-1150 Link Here
1144
  if (l == 0)
1144
  if (l == 0)
1145
    {
1145
    {
1146
      if (!null_string) {
1146
      if (!null_string) {
1147
        if((null_string = (char *)malloc(1)) == NULL) {
1147
        if((null_string = (char *)SMB_MALLOC(1)) == NULL) {
1148
          DEBUG(0,("string_init: malloc fail for null_string.\n"));
1148
          DEBUG(0,("string_init: malloc fail for null_string.\n"));
1149
          return False;
1149
          return False;
1150
        }
1150
        }
Lines 1154-1160 Link Here
1154
    }
1154
    }
1155
  else
1155
  else
1156
    {
1156
    {
1157
      (*dest) = (char *)malloc(l+1);
1157
      (*dest) = (char *)SMB_MALLOC(l+1);
1158
      if ((*dest) == NULL) {
1158
      if ((*dest) == NULL) {
1159
	      DEBUG(0,("Out of memory in string_init\n"));
1159
	      DEBUG(0,("Out of memory in string_init\n"));
1160
	      return False;
1160
	      return False;
Lines 1360-1366 Link Here
1360
	char *s;
1360
	char *s;
1361
	int i, j;
1361
	int i, j;
1362
	const char *hex = "0123456789ABCDEF";
1362
	const char *hex = "0123456789ABCDEF";
1363
	s = malloc(len * 3 + 1);
1363
1364
	if(len <= 0 || len >= (INT_MAX/3)-1)
1365
	    return NULL;
1366
	s = SMB_MALLOC(len * 3 + 1);
1364
	if (!s) return NULL;
1367
	if (!s) return NULL;
1365
	for (j=i=0;i<len;i++) {
1368
	for (j=i=0;i<len;i++) {
1366
		s[j] = '\\';
1369
		s[j] = '\\';
Lines 1396-1402 Link Here
1396
	char *ret;
1399
	char *ret;
1397
1400
1398
	n = strnlen(s, n);
1401
	n = strnlen(s, n);
1399
	ret = malloc(n+1);
1402
	ret = SMB_MALLOC(n+1);
1400
	if (!ret)
1403
	if (!ret)
1401
		return NULL;
1404
		return NULL;
1402
	memcpy(ret, s, n);
1405
	memcpy(ret, s, n);
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/util_unistr.c (-12 / +16 lines)
Lines 569-575 Link Here
569
569
570
  free_maps(pp_cp_to_ucs2, pp_ucs2_to_cp);
570
  free_maps(pp_cp_to_ucs2, pp_ucs2_to_cp);
571
571
572
  if ((*pp_ucs2_to_cp = (uint16 *)malloc(2*65536)) == NULL) {
572
  if ((*pp_ucs2_to_cp = SMB_MALLOC_ARRAY( uint16, 65536 )) == NULL) {
573
    DEBUG(0,("default_unicode_map: malloc fail for ucs2_to_cp size %u.\n", 2*65536));
573
    DEBUG(0,("default_unicode_map: malloc fail for ucs2_to_cp size %u.\n", 2*65536));
574
    abort();
574
    abort();
575
  }
575
  }
Lines 673-684 Link Here
673
673
674
  free_maps(pp_cp_to_ucs2, pp_ucs2_to_cp);
674
  free_maps(pp_cp_to_ucs2, pp_ucs2_to_cp);
675
675
676
  if ((cp_to_ucs2 = (smb_ucs2_t *)malloc(cp_to_ucs2_size)) == NULL) {
676
  if ((cp_to_ucs2 = (smb_ucs2_t *)SMB_MALLOC(cp_to_ucs2_size)) == NULL) {
677
    DEBUG(0,("load_unicode_map: malloc fail for cp_to_ucs2 size %u.\n", cp_to_ucs2_size ));
677
    DEBUG(0,("load_unicode_map: malloc fail for cp_to_ucs2 size %u.\n", cp_to_ucs2_size ));
678
    goto clean_and_exit;
678
    goto clean_and_exit;
679
  }
679
  }
680
680
681
  if ((ucs2_to_cp = (uint16 *)malloc(ucs2_to_cp_size)) == NULL) {
681
  if ((ucs2_to_cp = (uint16 *)SMB_MALLOC(ucs2_to_cp_size)) == NULL) {
682
    DEBUG(0,("load_unicode_map: malloc fail for ucs2_to_cp size %u.\n", ucs2_to_cp_size ));
682
    DEBUG(0,("load_unicode_map: malloc fail for ucs2_to_cp size %u.\n", ucs2_to_cp_size ));
683
    goto clean_and_exit;
683
    goto clean_and_exit;
684
  }
684
  }
Lines 1150-1161 Link Here
1150
1150
1151
smb_ucs2_t *strdup_w(const smb_ucs2_t *s)
1151
smb_ucs2_t *strdup_w(const smb_ucs2_t *s)
1152
{
1152
{
1153
	size_t newlen = (strlen_w(s)+1)*sizeof(smb_ucs2_t);
1153
	size_t newlen;
1154
	smb_ucs2_t *newstr = (smb_ucs2_t *)malloc(newlen);
1154
	smb_ucs2_t *newstr;
1155
    if (newstr == NULL)
1155
1156
        return NULL;
1156
	newstr = SMB_MALLOC_ARRAY(smb_ucs2_t, strlen_w(s)+1 );
1157
    safe_strcpy_w(newstr, s, newlen);
1157
1158
    return newstr;
1158
	if (newstr == NULL)
1159
	    return NULL;
1160
	newlen = (strlen_w(s)+1)*sizeof(smb_ucs2_t);
1161
	safe_strcpy_w(newstr, s, newlen);
1162
	return newstr;
1159
}
1163
}
1160
1164
1161
/*******************************************************************
1165
/*******************************************************************
Lines 1382-1388 Link Here
1382
	*ctok = ictok;
1386
	*ctok = ictok;
1383
	s = last_ptr;
1387
	s = last_ptr;
1384
1388
1385
	if (!(ret=iret=malloc(ictok*sizeof(smb_ucs2_t *))))
1389
	if (!(ret=iret=SMB_MALLOC_ARRAY( smb_ucs2_t *, ictok )))
1386
		return NULL;
1390
		return NULL;
1387
  
1391
  
1388
	while(ictok--) {
1392
	while(ictok--) {
Lines 1855-1861 Link Here
1855
	size_t l;
1859
	size_t l;
1856
1860
1857
	if (!null_string) {
1861
	if (!null_string) {
1858
		if((null_string = (smb_ucs2_t *)malloc(sizeof(smb_ucs2_t))) == NULL) {
1862
		if((null_string = SMB_MALLOC_P(smb_ucs2_t)) == NULL) {
1859
			DEBUG(0,("string_init_w: malloc fail for null_string.\n"));
1863
			DEBUG(0,("string_init_w: malloc fail for null_string.\n"));
1860
		return False;
1864
		return False;
1861
		}
1865
		}
Lines 1870-1876 Link Here
1870
	if (l == 0)
1874
	if (l == 0)
1871
		*dest = null_string;
1875
		*dest = null_string;
1872
	else {
1876
	else {
1873
		(*dest) = (smb_ucs2_t *)malloc(sizeof(smb_ucs2_t)*(l+1));
1877
		(*dest) = SMB_MALLOC_ARRAY( smb_ucs2_t, l+1 );
1874
		if ((*dest) == NULL) {
1878
		if ((*dest) == NULL) {
1875
			DEBUG(0,("Out of memory in string_init_w\n"));
1879
			DEBUG(0,("Out of memory in string_init_w\n"));
1876
			return False;
1880
			return False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/lib/wins_srv.c (-2 / +2 lines)
Lines 139-145 Link Here
139
  DEBUG( 4, ("wins_srv_load_list(): Building WINS server list:\n") );
139
  DEBUG( 4, ("wins_srv_load_list(): Building WINS server list:\n") );
140
  while( next_token( &p, wins_id_bufr, LIST_SEP, sizeof( wins_id_bufr ) ) )
140
  while( next_token( &p, wins_id_bufr, LIST_SEP, sizeof( wins_id_bufr ) ) )
141
    {
141
    {
142
    entry = (list_entry *)malloc( sizeof( list_entry ) );
142
    entry = SMB_MALLOC_P(list_entry);
143
    if( NULL == entry )
143
    if( NULL == entry )
144
      {
144
      {
145
      DEBUG( 0, ("wins_srv_load_list(): malloc(list_entry) failed.\n") );
145
      DEBUG( 0, ("wins_srv_load_list(): malloc(list_entry) failed.\n") );
Lines 147-153 Link Here
147
    else
147
    else
148
      {
148
      {
149
      entry->mourning = 0;
149
      entry->mourning = 0;
150
      if( NULL == (entry->server = strdup( wins_id_bufr )) )
150
      if( NULL == (entry->server = SMB_STRDUP( wins_id_bufr )) )
151
        {
151
        {
152
        SAFE_FREE( entry );
152
        SAFE_FREE( entry );
153
        DEBUG( 0, ("wins_srv_load_list(): strdup(\"%s\") failed.\n", wins_id_bufr) );
153
        DEBUG( 0, ("wins_srv_load_list(): strdup(\"%s\") failed.\n", wins_id_bufr) );
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/cli_lsarpc.c (-19 / +12 lines)
Lines 282-303 Link Here
282
		goto done;
282
		goto done;
283
	}
283
	}
284
284
285
	if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) *
285
	if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
286
					   num_sids))) {
287
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
286
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
288
		result = NT_STATUS_UNSUCCESSFUL;
287
		result = NT_STATUS_UNSUCCESSFUL;
289
		goto done;
288
		goto done;
290
	}
289
	}
291
290
292
	if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) *
291
	if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
293
					 num_sids))) {
294
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
292
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
295
		result = NT_STATUS_UNSUCCESSFUL;
293
		result = NT_STATUS_UNSUCCESSFUL;
296
		goto done;
294
		goto done;
297
	}
295
	}
298
296
299
	if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
297
	if (!((*types) = TALLOC_ARRAY(mem_ctx, uint32, num_sids))) {
300
					  num_sids))) {
301
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
298
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
302
		result = NT_STATUS_UNSUCCESSFUL;
299
		result = NT_STATUS_UNSUCCESSFUL;
303
		goto done;
300
		goto done;
Lines 400-414 Link Here
400
		goto done;
397
		goto done;
401
	}
398
	}
402
399
403
	if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
400
	if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) {
404
					 num_names)))) {
405
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
401
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
406
		result = NT_STATUS_UNSUCCESSFUL;
402
		result = NT_STATUS_UNSUCCESSFUL;
407
		goto done;
403
		goto done;
408
	}
404
	}
409
405
410
	if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
406
	if (!((*types = TALLOC_ARRAY(mem_ctx, uint32, num_names)))) {
411
					 num_names)))) {
412
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
407
		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
413
		result = NT_STATUS_UNSUCCESSFUL;
408
		result = NT_STATUS_UNSUCCESSFUL;
414
		goto done;
409
		goto done;
Lines 589-596 Link Here
589
584
590
		/* Allocate memory for trusted domain names and sids */
585
		/* Allocate memory for trusted domain names and sids */
591
586
592
		*domain_names = (char **)talloc(mem_ctx, sizeof(char *) *
587
		*domain_names = TALLOC_ARRAY(mem_ctx, char *, r.num_domains);
593
						r.num_domains);
594
588
595
		if (!*domain_names) {
589
		if (!*domain_names) {
596
			DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
590
			DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
Lines 598-605 Link Here
598
			goto done;
592
			goto done;
599
		}
593
		}
600
594
601
		*domain_sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
595
		*domain_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.num_domains);
602
						 r.num_domains);
603
		if (!domain_sids) {
596
		if (!domain_sids) {
604
			DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
597
			DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
605
			result = NT_STATUS_UNSUCCESSFUL;
598
			result = NT_STATUS_UNSUCCESSFUL;
Lines 674-692 Link Here
674
	*enum_context = r.enum_context;
667
	*enum_context = r.enum_context;
675
	*count = r.count;
668
	*count = r.count;
676
669
677
	if (!((*privs_name = (char **)talloc(mem_ctx, sizeof(char *) * r.count)))) {
670
	if (!((*privs_name = TALLOC_ARRAY(mem_ctx, char *, r.count)))) {
678
		DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
671
		DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
679
		result = NT_STATUS_UNSUCCESSFUL;
672
		result = NT_STATUS_UNSUCCESSFUL;
680
		goto done;
673
		goto done;
681
	}
674
	}
682
675
683
	if (!((*privs_high = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
676
	if (!((*privs_high = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
684
		DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
677
		DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
685
		result = NT_STATUS_UNSUCCESSFUL;
678
		result = NT_STATUS_UNSUCCESSFUL;
686
		goto done;
679
		goto done;
687
	}
680
	}
688
681
689
	if (!((*privs_low = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
682
	if (!((*privs_low = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
690
		DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
683
		DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
691
		result = NT_STATUS_UNSUCCESSFUL;
684
		result = NT_STATUS_UNSUCCESSFUL;
692
		goto done;
685
		goto done;
Lines 810-816 Link Here
810
803
811
	/* Return output parameters */
804
	/* Return output parameters */
812
805
813
	*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.sids.num_entries);
806
	*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.sids.num_entries);
814
	if (!*sids) {
807
	if (!*sids) {
815
		DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
808
		DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
816
		result = NT_STATUS_UNSUCCESSFUL;
809
		result = NT_STATUS_UNSUCCESSFUL;
Lines 935-941 Link Here
935
	if (r.count == 0)
928
	if (r.count == 0)
936
		goto done;
929
		goto done;
937
930
938
	if (!((*set = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR) * r.count)))) {
931
	if (!((*set = TALLOC_ARRAY(mem_ctx, LUID_ATTR, r.count)))) {
939
		DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
932
		DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
940
		result = NT_STATUS_UNSUCCESSFUL;
933
		result = NT_STATUS_UNSUCCESSFUL;
941
		goto done;
934
		goto done;
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/cli_samr.c (-9 / +7 lines)
Lines 551-558 Link Here
551
551
552
	*num_dom_groups = r.num_entries2;
552
	*num_dom_groups = r.num_entries2;
553
553
554
	if (!((*dom_groups) = (struct acct_info *)
554
	if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
555
	      talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
556
		result = NT_STATUS_UNSUCCESSFUL;
555
		result = NT_STATUS_UNSUCCESSFUL;
557
		goto done;
556
		goto done;
558
	}
557
	}
Lines 629-636 Link Here
629
628
630
	*num_dom_groups = r.num_entries2;
629
	*num_dom_groups = r.num_entries2;
631
630
632
	if (!((*dom_groups) = (struct acct_info *)
631
	if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
633
	      talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
634
		result = NT_STATUS_UNSUCCESSFUL;
632
		result = NT_STATUS_UNSUCCESSFUL;
635
		goto done;
633
		goto done;
636
	}
634
	}
Lines 703-709 Link Here
703
701
704
	*num_mem = r.num_sids;
702
	*num_mem = r.num_sids;
705
703
706
	if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
704
	if (!(*sids = TALLOC_ARRAY(mem_ctx,DOM_SID, *num_mem))) {
707
		result = NT_STATUS_UNSUCCESSFUL;
705
		result = NT_STATUS_UNSUCCESSFUL;
708
		goto done;
706
		goto done;
709
	}
707
	}
Lines 972-979 Link Here
972
	}
970
	}
973
971
974
	*num_names = r.num_names1;
972
	*num_names = r.num_names1;
975
	*names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
973
	*names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
976
	*name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
974
	*name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
977
975
978
	for (i = 0; i < r.num_names1; i++) {
976
	for (i = 0; i < r.num_names1; i++) {
979
		fstring tmp;
977
		fstring tmp;
Lines 1040-1047 Link Here
1040
	}
1038
	}
1041
1039
1042
	*num_rids = r.num_rids1;
1040
	*num_rids = r.num_rids1;
1043
	*rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1041
	*rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1044
	*rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1042
	*rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1045
1043
1046
	for (i = 0; i < r.num_rids1; i++) {
1044
	for (i = 0; i < r.num_rids1; i++) {
1047
		(*rids)[i] = r.rids[i];
1045
		(*rids)[i] = r.rids[i];
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/cli_spoolss.c (-11 / +11 lines)
Lines 70-76 Link Here
70
        uint32 i;
70
        uint32 i;
71
        PRINTER_INFO_0  *inf;
71
        PRINTER_INFO_0  *inf;
72
72
73
        inf=(PRINTER_INFO_0 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_0));
73
        inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
74
74
75
        buffer->prs.data_offset=0;
75
        buffer->prs.data_offset=0;
76
76
Lines 89-95 Link Here
89
        uint32 i;
89
        uint32 i;
90
        PRINTER_INFO_1  *inf;
90
        PRINTER_INFO_1  *inf;
91
91
92
        inf=(PRINTER_INFO_1 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_1));
92
        inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
93
93
94
        buffer->prs.data_offset=0;
94
        buffer->prs.data_offset=0;
95
95
Lines 108-114 Link Here
108
        uint32 i;
108
        uint32 i;
109
        PRINTER_INFO_2  *inf;
109
        PRINTER_INFO_2  *inf;
110
110
111
        inf=(PRINTER_INFO_2 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_2));
111
        inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
112
112
113
        buffer->prs.data_offset=0;
113
        buffer->prs.data_offset=0;
114
114
Lines 129-135 Link Here
129
        uint32 i;
129
        uint32 i;
130
        PRINTER_INFO_3  *inf;
130
        PRINTER_INFO_3  *inf;
131
131
132
        inf=(PRINTER_INFO_3 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_3));
132
        inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
133
133
134
        buffer->prs.data_offset=0;
134
        buffer->prs.data_offset=0;
135
135
Lines 149-155 Link Here
149
        uint32 i;
149
        uint32 i;
150
        PORT_INFO_1 *inf;
150
        PORT_INFO_1 *inf;
151
151
152
        inf=(PORT_INFO_1*)talloc(mem_ctx, returned*sizeof(PORT_INFO_1));
152
        inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
153
153
154
        prs_set_offset(&buffer->prs, 0);
154
        prs_set_offset(&buffer->prs, 0);
155
155
Lines 168-174 Link Here
168
        uint32 i;
168
        uint32 i;
169
        PORT_INFO_2 *inf;
169
        PORT_INFO_2 *inf;
170
170
171
        inf=(PORT_INFO_2*)talloc(mem_ctx, returned*sizeof(PORT_INFO_2));
171
        inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
172
172
173
        prs_set_offset(&buffer->prs, 0);
173
        prs_set_offset(&buffer->prs, 0);
174
174
Lines 187-193 Link Here
187
        uint32 i;
187
        uint32 i;
188
        DRIVER_INFO_1 *inf;
188
        DRIVER_INFO_1 *inf;
189
189
190
        inf=(DRIVER_INFO_1 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_1));
190
        inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
191
191
192
        buffer->prs.data_offset=0;
192
        buffer->prs.data_offset=0;
193
193
Lines 206-212 Link Here
206
        uint32 i;
206
        uint32 i;
207
        DRIVER_INFO_2 *inf;
207
        DRIVER_INFO_2 *inf;
208
208
209
        inf=(DRIVER_INFO_2 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_2));
209
        inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
210
210
211
        buffer->prs.data_offset=0;
211
        buffer->prs.data_offset=0;
212
212
Lines 225-231 Link Here
225
        uint32 i;
225
        uint32 i;
226
        DRIVER_INFO_3 *inf;
226
        DRIVER_INFO_3 *inf;
227
227
228
        inf=(DRIVER_INFO_3 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_3));
228
        inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
229
229
230
        buffer->prs.data_offset=0;
230
        buffer->prs.data_offset=0;
231
231
Lines 244-250 Link Here
244
{
244
{
245
	DRIVER_DIRECTORY_1 *inf;
245
	DRIVER_DIRECTORY_1 *inf;
246
 
246
 
247
        inf=(DRIVER_DIRECTORY_1 *)talloc(mem_ctx, sizeof(DRIVER_DIRECTORY_1));
247
        inf=TALLOC_P(mem_ctx, DRIVER_DIRECTORY_1);
248
248
249
        prs_set_offset(&buffer->prs, 0);
249
        prs_set_offset(&buffer->prs, 0);
250
250
Lines 1415-1421 Link Here
1415
{
1415
{
1416
	int i;
1416
	int i;
1417
1417
1418
	*forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1));
1418
	*forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
1419
	buffer->prs.data_offset = 0;
1419
	buffer->prs.data_offset = 0;
1420
1420
1421
	for (i = 0; i < num_forms; i++)
1421
	for (i = 0; i < num_forms; i++)
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/clientgen.c (-3 / +3 lines)
Lines 174-180 Link Here
174
	}
174
	}
175
175
176
	if (!cli) {
176
	if (!cli) {
177
		cli = (struct cli_state *)malloc(sizeof(*cli));
177
		cli = SMB_MALLOC_P(struct cli_state);
178
		if (!cli)
178
		if (!cli)
179
			return NULL;
179
			return NULL;
180
		ZERO_STRUCTP(cli);
180
		ZERO_STRUCTP(cli);
Lines 196-203 Link Here
196
	cli->timeout = 20000; /* Timeout is in milliseconds. */
196
	cli->timeout = 20000; /* Timeout is in milliseconds. */
197
	cli->bufsize = CLI_BUFFER_SIZE+4;
197
	cli->bufsize = CLI_BUFFER_SIZE+4;
198
	cli->max_xmit = cli->bufsize;
198
	cli->max_xmit = cli->bufsize;
199
	cli->outbuf = (char *)malloc(cli->bufsize);
199
	cli->outbuf = (char *)SMB_MALLOC(cli->bufsize);
200
	cli->inbuf = (char *)malloc(cli->bufsize);
200
	cli->inbuf = (char *)SMB_MALLOC(cli->bufsize);
201
	cli->oplock_handler = cli_oplock_ack;
201
	cli->oplock_handler = cli_oplock_ack;
202
	/* Set the CLI_FORCE_DOSERR environment variable to test
202
	/* Set the CLI_FORCE_DOSERR environment variable to test
203
	   client routines using DOS errors instead of STATUS32
203
	   client routines using DOS errors instead of STATUS32
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/clifile.c (-1 / +1 lines)
Lines 1045-1051 Link Here
1045
		pstring path2;
1045
		pstring path2;
1046
		clistr_pull(cli, path2, p, 
1046
		clistr_pull(cli, path2, p, 
1047
			    sizeof(path2), len, STR_ASCII);
1047
			    sizeof(path2), len, STR_ASCII);
1048
		*tmp_path = strdup(path2);
1048
		*tmp_path = SMB_STRDUP(path2);
1049
	}
1049
	}
1050
1050
1051
	return SVAL(cli->inbuf,smb_vwv0);
1051
	return SVAL(cli->inbuf,smb_vwv0);
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/clilist.c (-2 / +6 lines)
Lines 263-269 Link Here
263
		}
263
		}
264
 
264
 
265
		/* and add them to the dirlist pool */
265
		/* and add them to the dirlist pool */
266
		tdl = Realloc(dirlist,dirlist_len + data_len);
266
		if(dirlist_len >= UINT_MAX - data_len) {
267
			DEBUG(0,("cli_list_new: integer overflow detected.\n"));
268
			break;
269
		}
270
		tdl = SMB_REALLOC(dirlist,dirlist_len + data_len);
267
271
268
		if (!tdl) {
272
		if (!tdl) {
269
			DEBUG(0,("cli_list_new: Failed to expand dirlist\n"));
273
			DEBUG(0,("cli_list_new: Failed to expand dirlist\n"));
Lines 391-397 Link Here
391
395
392
		first = False;
396
		first = False;
393
397
394
		tdl = Realloc(dirlist,(num_received + received)*DIR_STRUCT_SIZE);
398
		tdl = SMB_REALLOC(dirlist,(num_received + received)*DIR_STRUCT_SIZE);
395
399
396
		if (!tdl) {
400
		if (!tdl) {
397
			DEBUG(0,("cli_list_old: failed to expand dirlist"));
401
			DEBUG(0,("cli_list_old: failed to expand dirlist"));
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/clireadwrite.c (-2 / +2 lines)
Lines 241-248 Link Here
241
	BOOL bigoffset = False;
241
	BOOL bigoffset = False;
242
242
243
	if (size > cli->bufsize) {
243
	if (size > cli->bufsize) {
244
		cli->outbuf = realloc(cli->outbuf, size + 1024);
244
		cli->outbuf = SMB_REALLOC(cli->outbuf, size + 1024);
245
		cli->inbuf = realloc(cli->inbuf, size + 1024);
245
		cli->inbuf = SMB_REALLOC(cli->inbuf, size + 1024);
246
		if (cli->outbuf == NULL || cli->inbuf == NULL)
246
		if (cli->outbuf == NULL || cli->inbuf == NULL)
247
			return False;
247
			return False;
248
		cli->bufsize = size + 1024;
248
		cli->bufsize = size + 1024;
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/clitrans.c (-4 / +4 lines)
Lines 181-187 Link Here
181
181
182
	/* allocate it */
182
	/* allocate it */
183
	if (total_data!=0) {
183
	if (total_data!=0) {
184
		tdata = Realloc(*data,total_data);
184
		tdata = SMB_REALLOC(*data,total_data);
185
		if (!tdata) {
185
		if (!tdata) {
186
			DEBUG(0,("cli_receive_trans: failed to enlarge data buffer\n"));
186
			DEBUG(0,("cli_receive_trans: failed to enlarge data buffer\n"));
187
			return False;
187
			return False;
Lines 191-197 Link Here
191
	}
191
	}
192
192
193
	if (total_param!=0) {
193
	if (total_param!=0) {
194
		tparam = Realloc(*param,total_param);
194
		tparam = SMB_REALLOC(*param,total_param);
195
		if (!tparam) {
195
		if (!tparam) {
196
			DEBUG(0,("cli_receive_trans: failed to enlarge param buffer\n"));
196
			DEBUG(0,("cli_receive_trans: failed to enlarge param buffer\n"));
197
			return False;
197
			return False;
Lines 446-452 Link Here
446
446
447
	/* allocate it */
447
	/* allocate it */
448
	if (total_data) {
448
	if (total_data) {
449
		tdata = Realloc(*data,total_data);
449
		tdata = SMB_REALLOC(*data,total_data);
450
		if (!tdata) {
450
		if (!tdata) {
451
			DEBUG(0,("cli_receive_nt_trans: failed to enlarge data buffer to %d\n",total_data));
451
			DEBUG(0,("cli_receive_nt_trans: failed to enlarge data buffer to %d\n",total_data));
452
			return False;
452
			return False;
Lines 456-462 Link Here
456
	}
456
	}
457
457
458
	if (total_param) {
458
	if (total_param) {
459
		tparam = Realloc(*param,total_param);
459
		tparam = SMB_REALLOC(*param,total_param);
460
		if (!tparam) {
460
		if (!tparam) {
461
			DEBUG(0,("cli_receive_nt_trans: failed to enlarge param buffer to %d\n", total_param));
461
			DEBUG(0,("cli_receive_nt_trans: failed to enlarge param buffer to %d\n", total_param));
462
			return False;
462
			return False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/libsmbclient.c (-14 / +14 lines)
Lines 378-384 Link Here
378
  
378
  
379
	DEBUG(4,(" tconx ok\n"));
379
	DEBUG(4,(" tconx ok\n"));
380
  
380
  
381
	srv = (struct smbc_server *)malloc(sizeof(*srv));
381
	srv = SMB_MALLOC_P(struct smbc_server);
382
	if (!srv) {
382
	if (!srv) {
383
		errno = ENOMEM;
383
		errno = ENOMEM;
384
		goto failed;
384
		goto failed;
Lines 390-414 Link Here
390
390
391
	srv->dev = (dev_t)(str_checksum(server) ^ str_checksum(share));
391
	srv->dev = (dev_t)(str_checksum(server) ^ str_checksum(share));
392
392
393
	srv->server_name = strdup(server);
393
	srv->server_name = SMB_STRDUP(server);
394
	if (!srv->server_name) {
394
	if (!srv->server_name) {
395
		errno = ENOMEM;
395
		errno = ENOMEM;
396
		goto failed;
396
		goto failed;
397
	}
397
	}
398
398
399
	srv->share_name = strdup(share);
399
	srv->share_name = SMB_STRDUP(share);
400
	if (!srv->share_name) {
400
	if (!srv->share_name) {
401
		errno = ENOMEM;
401
		errno = ENOMEM;
402
		goto failed;
402
		goto failed;
403
	}
403
	}
404
404
405
	srv->workgroup = strdup(workgroup);
405
	srv->workgroup = SMB_STRDUP(workgroup);
406
	if (!srv->workgroup) {
406
	if (!srv->workgroup) {
407
		errno = ENOMEM;
407
		errno = ENOMEM;
408
		goto failed;
408
		goto failed;
409
	}
409
	}
410
410
411
	srv->username = strdup(username);
411
	srv->username = SMB_STRDUP(username);
412
	if (!srv->username) {
412
	if (!srv->username) {
413
		errno = ENOMEM;
413
		errno = ENOMEM;
414
		goto failed;
414
		goto failed;
Lines 535-541 Link Here
535
535
536
	user = getenv("USER");
536
	user = getenv("USER");
537
	/* walk around as "guest" if no username can be found */
537
	/* walk around as "guest" if no username can be found */
538
	if (!user) user = strdup("guest");
538
	if (!user) user = SMB_STRDUP("guest");
539
	pstrcpy(smbc_user, user); /* Save for use elsewhere */
539
	pstrcpy(smbc_user, user); /* Save for use elsewhere */
540
	
540
	
541
	/*
541
	/*
Lines 585-591 Link Here
585
585
586
#endif
586
#endif
587
587
588
	smbc_file_table = malloc(SMBC_MAX_FD * sizeof(struct smbc_file *));
588
	smbc_file_table = SMB_MALLOC_ARRAY( struct smbc_file *, SMBC_MAX_FD );
589
	if (!smbc_file_table)
589
	if (!smbc_file_table)
590
		return ENOMEM;
590
		return ENOMEM;
591
591
Lines 659-665 Link Here
659
659
660
		}
660
		}
661
661
662
		smbc_file_table[slot] = malloc(sizeof(struct smbc_file));
662
		smbc_file_table[slot] = SMB_MALLOC_P(struct smbc_file);
663
663
664
		if (!smbc_file_table[slot]) {
664
		if (!smbc_file_table[slot]) {
665
665
Lines 682-688 Link Here
682
682
683
		smbc_file_table[slot]->cli_fd  = fd;
683
		smbc_file_table[slot]->cli_fd  = fd;
684
		smbc_file_table[slot]->smbc_fd = slot + smbc_start_fd;
684
		smbc_file_table[slot]->smbc_fd = slot + smbc_start_fd;
685
		smbc_file_table[slot]->fname   = strdup(fname);
685
		smbc_file_table[slot]->fname   = SMB_STRDUP(fname);
686
		smbc_file_table[slot]->srv     = srv;
686
		smbc_file_table[slot]->srv     = srv;
687
		smbc_file_table[slot]->offset  = 0;
687
		smbc_file_table[slot]->offset  = 0;
688
		smbc_file_table[slot]->file    = True;
688
		smbc_file_table[slot]->file    = True;
Lines 1419-1425 Link Here
1419
	size = sizeof(struct smbc_dirent) + (name?strlen(name):0) +
1419
	size = sizeof(struct smbc_dirent) + (name?strlen(name):0) +
1420
		(comment?strlen(comment):0) + 1; 
1420
		(comment?strlen(comment):0) + 1; 
1421
    
1421
    
1422
	dirent = malloc(size);
1422
	dirent = SMB_MALLOC(size);
1423
1423
1424
	if (!dirent) {
1424
	if (!dirent) {
1425
1425
Lines 1430-1436 Link Here
1430
1430
1431
	if (dir->dir_list == NULL) {
1431
	if (dir->dir_list == NULL) {
1432
1432
1433
		dir->dir_list = malloc(sizeof(struct smbc_dir_list));
1433
		dir->dir_list = SMB_MALLOC_P(struct smbc_dir_list);
1434
		if (!dir->dir_list) {
1434
		if (!dir->dir_list) {
1435
1435
1436
			SAFE_FREE(dirent);
1436
			SAFE_FREE(dirent);
Lines 1444-1450 Link Here
1444
	}
1444
	}
1445
	else {
1445
	else {
1446
1446
1447
		dir->dir_end->next = malloc(sizeof(struct smbc_dir_list));
1447
		dir->dir_end->next = SMB_MALLOC_P(struct smbc_dir_list);
1448
		
1448
		
1449
		if (!dir->dir_end->next) {
1449
		if (!dir->dir_end->next) {
1450
			
1450
			
Lines 1581-1587 Link Here
1581
      
1581
      
1582
	}
1582
	}
1583
1583
1584
	smbc_file_table[slot] = malloc(sizeof(struct smbc_file));
1584
	smbc_file_table[slot] = SMB_MALLOC_P(struct smbc_file);
1585
1585
1586
	if (!smbc_file_table[slot]) {
1586
	if (!smbc_file_table[slot]) {
1587
1587
Lines 1592-1598 Link Here
1592
1592
1593
	smbc_file_table[slot]->cli_fd   = 0;
1593
	smbc_file_table[slot]->cli_fd   = 0;
1594
	smbc_file_table[slot]->smbc_fd  = slot + smbc_start_fd;
1594
	smbc_file_table[slot]->smbc_fd  = slot + smbc_start_fd;
1595
	smbc_file_table[slot]->fname    = strdup(fname);
1595
	smbc_file_table[slot]->fname    = SMB_STRDUP(fname);
1596
	smbc_file_table[slot]->srv      = NULL;
1596
	smbc_file_table[slot]->srv      = NULL;
1597
	smbc_file_table[slot]->offset   = 0;
1597
	smbc_file_table[slot]->offset   = 0;
1598
	smbc_file_table[slot]->file     = False;
1598
	smbc_file_table[slot]->file     = False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/namecache.c (-3 / +2 lines)
Lines 98-104 Link Here
98
	if (num_names > 0)
98
	if (num_names > 0)
99
		size += sizeof(struct in_addr) * (num_names-1);
99
		size += sizeof(struct in_addr) * (num_names-1);
100
100
101
	value = (struct nc_value *)malloc(size);
101
	value = (struct nc_value *)SMB_MALLOC(size);
102
102
103
	memset(value, 0, size);
103
	memset(value, 0, size);
104
104
Lines 224-231 Link Here
224
224
225
	if (data->count) {
225
	if (data->count) {
226
226
227
		*ip_list = (struct in_addr *)malloc(
227
		*ip_list = SMB_MALLOC_ARRAY(struct in_addr, data->count);
228
			sizeof(struct in_addr) * data->count);
229
		
228
		
230
		memcpy(*ip_list, data->ip_list, sizeof(struct in_addr) * data->count);
229
		memcpy(*ip_list, data->ip_list, sizeof(struct in_addr) * data->count);
231
		
230
		
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/namequery.c (-11 / +19 lines)
Lines 54-60 Link Here
54
54
55
	if (*num_names == 0) return NULL;
55
	if (*num_names == 0) return NULL;
56
56
57
	ret = (struct node_status *)malloc(sizeof(struct node_status)* (*num_names));
57
	ret = SMB_MALLOC_ARRAY(struct node_status, *num_names);
58
	if (!ret) return NULL;
58
	if (!ret) return NULL;
59
59
60
	p++;
60
	p++;
Lines 238-244 Link Here
238
238
239
  /* Now, create the additional stuff for a registration request */
239
  /* Now, create the additional stuff for a registration request */
240
240
241
  if ((nmb->additional = (struct res_rec *)malloc(sizeof(struct res_rec))) == NULL) {
241
  if ((nmb->additional = SMB_MALLOC_P(struct res_rec)) == NULL) {
242
242
243
    DEBUG(0, ("name_register: malloc fail for additional record.\n"));
243
    DEBUG(0, ("name_register: malloc fail for additional record.\n"));
244
    return False;
244
    return False;
Lines 407-414 Link Here
407
				continue;
407
				continue;
408
			}
408
			}
409
409
410
			tmp_ip_list = (struct in_addr *)Realloc( ip_list, sizeof( ip_list[0] )
410
			if(
411
												* ( (*count) + nmb2->answers->rdlength/6 ) );
411
			   nmb2->answers->rdlength >= INT_MAX/6 ||
412
			   (*count) >= INT_MAX-(nmb2->answers->rdlength/6) ||
413
			   sizeof( ip_list[0] ) >= UINT_MAX/( (*count) + nmb2->answers->rdlength/6 )
414
			   )
415
			{
416
				DEBUG(0,("name_query: integer overflow detected.\n"));
417
				free_packet(p2);
418
				return NULL;
419
			}
420
			tmp_ip_list = SMB_REALLOC_ARRAY( ip_list, struct in_addr, (*count) + nmb2->answers->rdlength/6 );
412
421
413
			if (!tmp_ip_list) {
422
			if (!tmp_ip_list) {
414
				DEBUG(0,("name_query: Realloc failed.\n"));
423
				DEBUG(0,("name_query: Realloc failed.\n"));
Lines 775-781 Link Here
775
                ((name_type2 == -1) || (name_type == name_type2))
784
                ((name_type2 == -1) || (name_type == name_type2))
776
               ) {
785
               ) {
777
				endlmhosts(fp);
786
				endlmhosts(fp);
778
				*return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr));
787
				*return_iplist = SMB_MALLOC_P(struct in_addr);
779
				if(*return_iplist == NULL) {
788
				if(*return_iplist == NULL) {
780
					DEBUG(3,("resolve_lmhosts: malloc fail !\n"));
789
					DEBUG(3,("resolve_lmhosts: malloc fail !\n"));
781
					return False;
790
					return False;
Lines 812-818 Link Here
812
		int i = 0, j;
821
		int i = 0, j;
813
		while (hp->h_addr_list[i]) i++;
822
		while (hp->h_addr_list[i]) i++;
814
		DEBUG(10, ("%d addresses returned\n", i));
823
		DEBUG(10, ("%d addresses returned\n", i));
815
		*return_iplist = (struct in_addr *)malloc(i*sizeof(struct in_addr));
824
		*return_iplist = SMB_MALLOC_ARRAY(struct in_addr, i);
816
		if(*return_iplist == NULL) {
825
		if(*return_iplist == NULL) {
817
			DEBUG(3,("resolve_hosts: malloc fail !\n"));
826
			DEBUG(3,("resolve_hosts: malloc fail !\n"));
818
			return False;
827
			return False;
Lines 849-855 Link Here
849
  *return_count = 0;
858
  *return_count = 0;
850
859
851
  if (allzeros || allones || is_address) {
860
  if (allzeros || allones || is_address) {
852
	*return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr));
861
	*return_iplist = SMB_MALLOC_P(struct in_addr);
853
	if(*return_iplist == NULL) {
862
	if(*return_iplist == NULL) {
854
		DEBUG(3,("internal_resolve_name: malloc fail !\n"));
863
		DEBUG(3,("internal_resolve_name: malloc fail !\n"));
855
		return False;
864
		return False;
Lines 919-926 Link Here
919
     controllers including the PDC in iplist[1..n].  Iterating over
928
     controllers including the PDC in iplist[1..n].  Iterating over
920
     the iplist when the PDC is down will cause two sets of timeouts. */
929
     the iplist when the PDC is down will cause two sets of timeouts. */
921
930
922
  if (*return_count && (nodupes_iplist =
931
  if (*return_count && (nodupes_iplist = SMB_MALLOC_ARRAY(struct in_addr, *return_count))) {
923
			(struct in_addr *)malloc(sizeof(struct in_addr) * (*return_count)))) {
924
      int nodupes_count = 0;
932
      int nodupes_count = 0;
925
 
933
 
926
      /* Iterate over return_iplist looking for duplicates */
934
      /* Iterate over return_iplist looking for duplicates */
Lines 1327-1333 Link Here
1327
		if (num_addresses == 0)
1335
		if (num_addresses == 0)
1328
			return internal_resolve_name(group, name_type, ip_list, count);
1336
			return internal_resolve_name(group, name_type, ip_list, count);
1329
1337
1330
		return_iplist = (struct in_addr *)malloc(num_addresses * sizeof(struct in_addr));
1338
		return_iplist = SMB_MALLOC_ARRAY(struct in_addr, num_addresses);
1331
		if(return_iplist == NULL) {
1339
		if(return_iplist == NULL) {
1332
			DEBUG(3,("get_dc_list: malloc fail !\n"));
1340
			DEBUG(3,("get_dc_list: malloc fail !\n"));
1333
			return False;
1341
			return False;
Lines 1339-1345 Link Here
1339
			int count_more;
1347
			int count_more;
1340
			if (resolve_name_2( name, &more_ip, &count_more, 0x20) == False)
1348
			if (resolve_name_2( name, &more_ip, &count_more, 0x20) == False)
1341
				continue;
1349
				continue;
1342
			tmp = (struct in_addr *)realloc(return_iplist,(num_addresses + count_more) * sizeof(struct in_addr));
1350
			tmp = SMB_REALLOC_ARRAY(return_iplist, struct in_addr, num_addresses + count_more);
1343
			if (return_iplist == NULL) {
1351
			if (return_iplist == NULL) {
1344
				DEBUG(3, ("realloc failed with %d addresses\n", num_addresses + count_more));
1352
				DEBUG(3, ("realloc failed with %d addresses\n", num_addresses + count_more));
1345
				SAFE_FREE(return_iplist);
1353
				SAFE_FREE(return_iplist);
(-)samba-2.2.12-pre-CAN-2004-1154/source/libsmb/nmblib.c (-10 / +7 lines)
Lines 335-341 Link Here
335
				struct res_rec **recs, int count)
335
				struct res_rec **recs, int count)
336
{
336
{
337
  int i;
337
  int i;
338
  *recs = (struct res_rec *)malloc(sizeof(**recs)*count);
338
  *recs = SMB_MALLOC_ARRAY(struct res_rec, count);
339
  if (!*recs) return(False);
339
  if (!*recs) return(False);
340
340
341
  memset((char *)*recs,'\0',sizeof(**recs)*count);
341
  memset((char *)*recs,'\0',sizeof(**recs)*count);
Lines 525-531 Link Here
525
  struct nmb_packet *copy_nmb;
525
  struct nmb_packet *copy_nmb;
526
  struct packet_struct *pkt_copy;
526
  struct packet_struct *pkt_copy;
527
527
528
  if(( pkt_copy = (struct packet_struct *)malloc(sizeof(*packet))) == NULL)
528
  if(( pkt_copy = SMB_MALLOC_P(struct packet_struct)) == NULL)
529
  {
529
  {
530
    DEBUG(0,("copy_nmb_packet: malloc fail.\n"));
530
    DEBUG(0,("copy_nmb_packet: malloc fail.\n"));
531
    return NULL;
531
    return NULL;
Lines 550-573 Link Here
550
550
551
  if (nmb->answers)
551
  if (nmb->answers)
552
  {
552
  {
553
    if((copy_nmb->answers = (struct res_rec *)
553
    if((copy_nmb->answers = SMB_MALLOC_ARRAY(struct res_rec, nmb->header.ancount)) == NULL)
554
                  malloc(nmb->header.ancount * sizeof(struct res_rec))) == NULL)
555
      goto free_and_exit;
554
      goto free_and_exit;
556
    memcpy((char *)copy_nmb->answers, (char *)nmb->answers, 
555
    memcpy((char *)copy_nmb->answers, (char *)nmb->answers, 
557
           nmb->header.ancount * sizeof(struct res_rec));
556
           nmb->header.ancount * sizeof(struct res_rec));
558
  }
557
  }
559
  if (nmb->nsrecs)
558
  if (nmb->nsrecs)
560
  {
559
  {
561
    if((copy_nmb->nsrecs = (struct res_rec *)
560
    if((copy_nmb->nsrecs = SMB_MALLOC_ARRAY(struct res_rec, nmb->header.nscount)) == NULL)
562
                  malloc(nmb->header.nscount * sizeof(struct res_rec))) == NULL)
563
      goto free_and_exit;
561
      goto free_and_exit;
564
    memcpy((char *)copy_nmb->nsrecs, (char *)nmb->nsrecs, 
562
    memcpy((char *)copy_nmb->nsrecs, (char *)nmb->nsrecs, 
565
           nmb->header.nscount * sizeof(struct res_rec));
563
           nmb->header.nscount * sizeof(struct res_rec));
566
  }
564
  }
567
  if (nmb->additional)
565
  if (nmb->additional)
568
  {
566
  {
569
    if((copy_nmb->additional = (struct res_rec *)
567
    if((copy_nmb->additional = SMB_MALLOC_ARRAY(struct res_rec, nmb->header.arcount)) == NULL)
570
                  malloc(nmb->header.arcount * sizeof(struct res_rec))) == NULL)
571
      goto free_and_exit;
568
      goto free_and_exit;
572
    memcpy((char *)copy_nmb->additional, (char *)nmb->additional, 
569
    memcpy((char *)copy_nmb->additional, (char *)nmb->additional, 
573
           nmb->header.arcount * sizeof(struct res_rec));
570
           nmb->header.arcount * sizeof(struct res_rec));
Lines 593-599 Link Here
593
{ 
590
{ 
594
  struct packet_struct *pkt_copy;
591
  struct packet_struct *pkt_copy;
595
592
596
  if(( pkt_copy = (struct packet_struct *)malloc(sizeof(*packet))) == NULL)
593
  if(( pkt_copy = SMB_MALLOC_P(struct packet_struct)) == NULL)
597
  {
594
  {
598
    DEBUG(0,("copy_dgram_packet: malloc fail.\n"));
595
    DEBUG(0,("copy_dgram_packet: malloc fail.\n"));
599
    return NULL;
596
    return NULL;
Lines 667-673 Link Here
667
	struct packet_struct *p;
664
	struct packet_struct *p;
668
	BOOL ok=False;
665
	BOOL ok=False;
669
666
670
	p = (struct packet_struct *)malloc(sizeof(*p));
667
	p = SMB_MALLOC_P(struct packet_struct);
671
	if (!p) return(NULL);
668
	if (!p) return(NULL);
672
669
673
	p->next = NULL;
670
	p->next = NULL;
(-)samba-2.2.12-pre-CAN-2004-1154/source/locking/brlock.c (-1 / +1 lines)
Lines 355-361 Link Here
355
	}
355
	}
356
356
357
	/* no conflicts - add it to the list of locks */
357
	/* no conflicts - add it to the list of locks */
358
	tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(*locks));
358
	tp = SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(*locks));
359
	if (!tp) {
359
	if (!tp) {
360
		status = NT_STATUS_NO_MEMORY;
360
		status = NT_STATUS_NO_MEMORY;
361
		goto fail;
361
		goto fail;
(-)samba-2.2.12-pre-CAN-2004-1154/source/locking/locking.c (-2 / +2 lines)
Lines 683-689 Link Here
683
		pstrcat(fname, fsp->fsp_name);
683
		pstrcat(fname, fsp->fsp_name);
684
684
685
		size = sizeof(*data) + sizeof(share_mode_entry) + strlen(fname) + 1;
685
		size = sizeof(*data) + sizeof(share_mode_entry) + strlen(fname) + 1;
686
		p = (char *)malloc(size);
686
		p = (char *)SMB_MALLOC(size);
687
		if (!p)
687
		if (!p)
688
			return False;
688
			return False;
689
		data = (struct locking_data *)p;
689
		data = (struct locking_data *)p;
Lines 715-721 Link Here
715
		fsp->fsp_name, data->u.num_share_mode_entries ));
715
		fsp->fsp_name, data->u.num_share_mode_entries ));
716
716
717
	size = dbuf.dsize + sizeof(share_mode_entry);
717
	size = dbuf.dsize + sizeof(share_mode_entry);
718
	p = malloc(size);
718
	p = SMB_MALLOC(size);
719
	if (!p)
719
	if (!p)
720
		return False;
720
		return False;
721
	memcpy(p, dbuf.dptr, sizeof(*data));
721
	memcpy(p, dbuf.dptr, sizeof(*data));
(-)samba-2.2.12-pre-CAN-2004-1154/source/locking/posix.c (-6 / +5 lines)
Lines 103-109 Link Here
103
103
104
	dbuf = tdb_fetch(posix_pending_close_tdb, kbuf);
104
	dbuf = tdb_fetch(posix_pending_close_tdb, kbuf);
105
105
106
	tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(int));
106
	tp = SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(int));
107
	if (!tp) {
107
	if (!tp) {
108
		DEBUG(0,("add_fd_to_close_entry: Realloc fail !\n"));
108
		DEBUG(0,("add_fd_to_close_entry: Realloc fail !\n"));
109
		SAFE_FREE(dbuf.dptr);
109
		SAFE_FREE(dbuf.dptr);
Lines 370-376 Link Here
370
	pl.size = size;
370
	pl.size = size;
371
	pl.lock_type = lock_type;
371
	pl.lock_type = lock_type;
372
372
373
	tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(pl));
373
	tp = SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(pl));
374
	if (!tp) {
374
	if (!tp) {
375
		DEBUG(0,("add_posix_lock_entry: Realloc fail !\n"));
375
		DEBUG(0,("add_posix_lock_entry: Realloc fail !\n"));
376
		goto fail;
376
		goto fail;
Lines 896-903 Link Here
896
        | l_curr|         | l_new   |
896
        | l_curr|         | l_new   |
897
        +-------+         +---------+
897
        +-------+         +---------+
898
**********************************************/
898
**********************************************/
899
				struct lock_list *l_new = (struct lock_list *)talloc(ctx,
899
				struct lock_list *l_new = TALLOC_P(ctx,struct lock_list);
900
													sizeof(struct lock_list));
901
900
902
				if(l_new == NULL) {
901
				if(l_new == NULL) {
903
					DEBUG(0,("posix_lock_list: talloc fail.\n"));
902
					DEBUG(0,("posix_lock_list: talloc fail.\n"));
Lines 1002-1008 Link Here
1002
		return True; /* Not a fatal error. */
1001
		return True; /* Not a fatal error. */
1003
	}
1002
	}
1004
1003
1005
	if ((ll = (struct lock_list *)talloc(l_ctx, sizeof(struct lock_list))) == NULL) {
1004
	if ((ll = TALLOC_P(l_ctx, struct lock_list)) == NULL) {
1006
		DEBUG(0,("set_posix_lock: unable to talloc unlock list.\n"));
1005
		DEBUG(0,("set_posix_lock: unable to talloc unlock list.\n"));
1007
		talloc_destroy(l_ctx);
1006
		talloc_destroy(l_ctx);
1008
		return True; /* Not a fatal error. */
1007
		return True; /* Not a fatal error. */
Lines 1148-1154 Link Here
1148
		return True; /* Not a fatal error. */
1147
		return True; /* Not a fatal error. */
1149
	}
1148
	}
1150
1149
1151
	if ((ul = (struct lock_list *)talloc(ul_ctx, sizeof(struct lock_list))) == NULL) {
1150
	if ((ul = TALLOC_P(ul_ctx, struct lock_list)) == NULL) {
1152
		DEBUG(0,("release_posix_lock: unable to talloc unlock list.\n"));
1151
		DEBUG(0,("release_posix_lock: unable to talloc unlock list.\n"));
1153
		talloc_destroy(ul_ctx);
1152
		talloc_destroy(ul_ctx);
1154
		return True; /* Not a fatal error. */
1153
		return True; /* Not a fatal error. */
(-)samba-2.2.12-pre-CAN-2004-1154/source/msdfs/msdfs.c (-2 / +2 lines)
Lines 457-463 Link Here
457
	/* add the unexplained 0x16 bytes */
457
	/* add the unexplained 0x16 bytes */
458
	reply_size += 0x16;
458
	reply_size += 0x16;
459
459
460
	pdata = Realloc(pdata,reply_size);
460
	pdata = SMB_REALLOC(pdata,reply_size);
461
	if(pdata == NULL) {
461
	if(pdata == NULL) {
462
		DEBUG(0,("malloc failed for Realloc!\n"));
462
		DEBUG(0,("malloc failed for Realloc!\n"));
463
		return -1;
463
		return -1;
Lines 536-542 Link Here
536
		reply_size += (strlen(junction->referral_list[i].alternate_path)+1)*2;
536
		reply_size += (strlen(junction->referral_list[i].alternate_path)+1)*2;
537
	}
537
	}
538
538
539
	pdata = Realloc(pdata,reply_size);
539
	pdata = SMB_REALLOC(pdata,reply_size);
540
	if(pdata == NULL) {
540
	if(pdata == NULL) {
541
		DEBUG(0,("version3 referral setup: malloc failed for Realloc!\n"));
541
		DEBUG(0,("version3 referral setup: malloc failed for Realloc!\n"));
542
		return -1;
542
		return -1;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd.c (-2 / +2 lines)
Lines 585-591 Link Here
585
    namecount++;
585
    namecount++;
586
586
587
  /* Allocate space for the netbios aliases */
587
  /* Allocate space for the netbios aliases */
588
  my_netbios_names = (char **)malloc( sizeof(char *) * (namecount+1) );
588
  my_netbios_names = SMB_MALLOC_ARRAY( char *, namecount+1 );
589
  if( NULL == my_netbios_names )
589
  if( NULL == my_netbios_names )
590
  {
590
  {
591
     DEBUG( 0, ( "init_structs: malloc fail.\n" ) );
591
     DEBUG( 0, ( "init_structs: malloc fail.\n" ) );
Lines 609-615 Link Here
609
        nodup=0;
609
        nodup=0;
610
    }
610
    }
611
    if (nodup)
611
    if (nodup)
612
      my_netbios_names[namecount++] = strdup( nbname );
612
      my_netbios_names[namecount++] = SMB_STRDUP( nbname );
613
  }
613
  }
614
  
614
  
615
  /* Check the strdups succeeded. */
615
  /* Check the strdups succeeded. */
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_become_lmb.c (-2 / +2 lines)
Lines 212-218 Link Here
212
    struct userdata_struct *userdata;
212
    struct userdata_struct *userdata;
213
    int size = sizeof(struct userdata_struct) + sizeof(BOOL);
213
    int size = sizeof(struct userdata_struct) + sizeof(BOOL);
214
214
215
    if((userdata = (struct userdata_struct *)malloc(size)) == NULL)
215
    if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL)
216
    {
216
    {
217
      DEBUG(0,("release_1d_name: malloc fail.\n"));
217
      DEBUG(0,("release_1d_name: malloc fail.\n"));
218
      return;
218
      return;
Lines 557-563 Link Here
557
  subrec->work_changed = True;
557
  subrec->work_changed = True;
558
558
559
  /* Setup the userdata_struct. */
559
  /* Setup the userdata_struct. */
560
  if((userdata = (struct userdata_struct *)malloc(size)) == NULL)
560
  if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL)
561
  {
561
  {
562
    DEBUG(0,("become_local_master_browser: malloc fail.\n"));
562
    DEBUG(0,("become_local_master_browser: malloc fail.\n"));
563
    return;
563
    return;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_browserdb.c (-1 / +1 lines)
Lines 89-95 Link Here
89
  struct browse_cache_record *browc;
89
  struct browse_cache_record *browc;
90
  time_t now = time( NULL );
90
  time_t now = time( NULL );
91
91
92
  browc = (struct browse_cache_record *)malloc( sizeof( *browc ) );
92
  browc = SMB_MALLOC_P( struct browse_cache_record );
93
93
94
  if( NULL == browc )
94
  if( NULL == browc )
95
    {
95
    {
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_browsesync.c (-1 / +1 lines)
Lines 329-335 Link Here
329
329
330
  /* Setup the userdata_struct - this is copied so we can use
330
  /* Setup the userdata_struct - this is copied so we can use
331
     a stack variable for this. */
331
     a stack variable for this. */
332
  if((userdata = (struct userdata_struct *)malloc(size)) == NULL)
332
  if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL)
333
  {
333
  {
334
    DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n"));
334
    DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n"));
335
    return;
335
    return;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_incomingrequests.c (-1 / +1 lines)
Lines 558-564 Link Here
558
        prdata = rdata;
558
        prdata = rdata;
559
      else
559
      else
560
      {
560
      {
561
        if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL)
561
        if((prdata = (char *)SMB_MALLOC( namerec->data.num_ips * 6 )) == NULL)
562
        {
562
        {
563
          DEBUG(0,("process_name_query_request: malloc fail !\n"));
563
          DEBUG(0,("process_name_query_request: malloc fail !\n"));
564
          goto done;
564
          goto done;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_namelistdb.c (-6 / +4 lines)
Lines 187-193 Link Here
187
  struct name_record *namerec;
187
  struct name_record *namerec;
188
  time_t time_now = time(NULL);
188
  time_t time_now = time(NULL);
189
189
190
  namerec = (struct name_record *)malloc( sizeof(*namerec) );
190
  namerec = SMB_MALLOC_P( struct name_record );
191
  if( NULL == namerec )
191
  if( NULL == namerec )
192
  {
192
  {
193
    DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) );
193
    DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) );
Lines 195-202 Link Here
195
  }
195
  }
196
196
197
  memset( (char *)namerec, '\0', sizeof(*namerec) );
197
  memset( (char *)namerec, '\0', sizeof(*namerec) );
198
  namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) 
198
  namerec->data.ip = SMB_MALLOC_ARRAY( struct in_addr, num_ips );
199
                                               * num_ips );
200
  if( NULL == namerec->data.ip )
199
  if( NULL == namerec->data.ip )
201
  {
200
  {
202
     DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) );
201
     DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) );
Lines 336-343 Link Here
336
  if( find_ip_in_name_record( namerec, new_ip ) )
335
  if( find_ip_in_name_record( namerec, new_ip ) )
337
    return;
336
    return;
338
  
337
  
339
  new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1)
338
  new_list = SMB_MALLOC_ARRAY( struct in_addr, namerec->data.num_ips + 1 );
340
                                       * sizeof(struct in_addr) );
341
  if( NULL == new_list )
339
  if( NULL == new_list )
342
  {
340
  {
343
    DEBUG(0,("add_ip_to_name_record: Malloc fail !\n"));
341
    DEBUG(0,("add_ip_to_name_record: Malloc fail !\n"));
Lines 492-498 Link Here
492
    /* Create an IP list containing all our known subnets. */
490
    /* Create an IP list containing all our known subnets. */
493
491
494
    num_ips = iface_count();
492
    num_ips = iface_count();
495
    iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) );
493
    iplist = SMB_MALLOC_ARRAY( struct in_addr, num_ips );
496
    if( NULL == iplist )
494
    if( NULL == iplist )
497
    {
495
    {
498
      DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n"));
496
      DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n"));
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_nameregister.c (-1 / +1 lines)
Lines 276-282 Link Here
276
  for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) )
276
  for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) )
277
    num_ips++;
277
    num_ips++;
278
278
279
  if((ip_list = (struct in_addr *)malloc(num_ips * sizeof(struct in_addr)))==NULL)
279
  if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips ))==NULL)
280
  {
280
  {
281
    DEBUG(0,("multihomed_register_name: malloc fail !\n"));
281
    DEBUG(0,("multihomed_register_name: malloc fail !\n"));
282
    return True;
282
    return True;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_packets.c (-4 / +9 lines)
Lines 193-199 Link Here
193
  struct nmb_packet *nmb = NULL;
193
  struct nmb_packet *nmb = NULL;
194
194
195
  /* Allocate the packet_struct we will return. */
195
  /* Allocate the packet_struct we will return. */
196
  if((packet = (struct packet_struct *)malloc(sizeof(*packet))) == NULL)
196
  if((packet = SMB_MALLOC_P(struct packet_struct)) == NULL)
197
  {
197
  {
198
    DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n"));
198
    DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n"));
199
    return NULL;
199
    return NULL;
Lines 240-246 Link Here
240
{
240
{
241
  struct nmb_packet *nmb = &packet->packet.nmb;
241
  struct nmb_packet *nmb = &packet->packet.nmb;
242
242
243
  if((nmb->additional = (struct res_rec *)malloc(sizeof(struct res_rec))) == NULL)
243
  if((nmb->additional = SMB_MALLOC_P(struct res_rec)) == NULL)
244
  {
244
  {
245
    DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n"));
245
    DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n"));
246
    return False;
246
    return False;
Lines 1705-1711 Link Here
1705
  struct subnet_record *subrec = NULL;
1705
  struct subnet_record *subrec = NULL;
1706
  int count = 0;
1706
  int count = 0;
1707
  int num = 0;
1707
  int num = 0;
1708
  fd_set *pset = (fd_set *)malloc(sizeof(fd_set));
1708
  fd_set *pset = SMB_MALLOC_P(fd_set);
1709
1709
1710
  if(pset == NULL)
1710
  if(pset == NULL)
1711
  {
1711
  {
Lines 1717-1722 Link Here
1717
  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
1717
  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
1718
    count++;
1718
    count++;
1719
1719
1720
  if(count >= (UINT_MAX/2)-2)
1721
  {
1722
    DEBUG(0,("create_listen_fdset: integer overflow detected.\n"));
1723
    return True;
1724
  }
1720
  if((count*2) + 2 > FD_SETSIZE)
1725
  if((count*2) + 2 > FD_SETSIZE)
1721
  {
1726
  {
1722
    DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \
1727
    DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \
Lines 1724-1730 Link Here
1724
    return True;
1729
    return True;
1725
  }
1730
  }
1726
1731
1727
  if((sock_array = (int *)malloc(((count*2) + 2)*sizeof(int))) == NULL)
1732
  if((sock_array = SMB_MALLOC_ARRAY( int, (count*2) + 2)) == NULL)
1728
  {
1733
  {
1729
    DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n"));
1734
    DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n"));
1730
    return True;
1735
    return True;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_responserecordsdb.c (-2 / +2 lines)
Lines 108-114 Link Here
108
  struct response_record *rrec;
108
  struct response_record *rrec;
109
  struct nmb_packet *nmb = &p->packet.nmb;
109
  struct nmb_packet *nmb = &p->packet.nmb;
110
110
111
  if (!(rrec = (struct response_record *)malloc(sizeof(*rrec)))) 
111
  if (!(rrec = SMB_MALLOC_P(struct response_record)))
112
  {
112
  {
113
    DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n"));
113
    DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n"));
114
    return NULL;
114
    return NULL;
Lines 142-148 Link Here
142
    {
142
    {
143
      /* Primitive userdata, do a memcpy. */
143
      /* Primitive userdata, do a memcpy. */
144
      if((rrec->userdata = (struct userdata_struct *)
144
      if((rrec->userdata = (struct userdata_struct *)
145
           malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL)
145
           SMB_MALLOC(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL)
146
      {
146
      {
147
        DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n"));
147
        DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n"));
148
	ZERO_STRUCTP(rrec);
148
	ZERO_STRUCTP(rrec);
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_serverlistdb.c (-1 / +1 lines)
Lines 148-154 Link Here
148
    return NULL;
148
    return NULL;
149
  }
149
  }
150
  
150
  
151
  if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL)
151
  if((servrec = SMB_MALLOC_P(struct server_record)) == NULL)
152
  {
152
  {
153
    DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n"));
153
    DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n"));
154
    return NULL;
154
    return NULL;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_subnetdb.c (-2 / +2 lines)
Lines 164-170 Link Here
164
164
165
  }
165
  }
166
166
167
  subrec = (struct subnet_record *)malloc(sizeof(*subrec));
167
  subrec = SMB_MALLOC_P(struct subnet_record);
168
  
168
  
169
  if (!subrec) 
169
  if (!subrec) 
170
  {
170
  {
Lines 179-185 Link Here
179
                        namelist_entry_compare,
179
                        namelist_entry_compare,
180
                        ubi_trOVERWRITE );
180
                        ubi_trOVERWRITE );
181
181
182
  if((subrec->subnet_name = strdup(name)) == NULL)
182
  if((subrec->subnet_name = SMB_STRDUP(name)) == NULL)
183
  {
183
  {
184
    DEBUG(0,("make_subnet: malloc fail for subnet name !\n"));
184
    DEBUG(0,("make_subnet: malloc fail for subnet name !\n"));
185
    close(nmb_sock);
185
    close(nmb_sock);
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_synclists.c (-1 / +1 lines)
Lines 146-152 Link Here
146
		return;
146
		return;
147
	}
147
	}
148
148
149
	s = (struct sync_record *)malloc(sizeof(*s));
149
	s = SMB_MALLOC_P(struct sync_record);
150
	if (!s) goto done;
150
	if (!s) goto done;
151
151
152
	ZERO_STRUCTP(s);
152
	ZERO_STRUCTP(s);
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_winsproxy.c (-2 / +2 lines)
Lines 61-67 Link Here
61
    iplist = &ip;
61
    iplist = &ip;
62
  else
62
  else
63
  {
63
  {
64
    if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL)
64
    if((iplist = SMB_MALLOC_ARRAY( struct in_addr, num_ips )) == NULL)
65
    {
65
    {
66
      DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n"));
66
      DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n"));
67
      return;
67
      return;
Lines 140-146 Link Here
140
{
140
{
141
  struct packet_struct *p, *copy_of_p;
141
  struct packet_struct *p, *copy_of_p;
142
  struct userdata_struct *new_userdata = 
142
  struct userdata_struct *new_userdata = 
143
        (struct userdata_struct *)malloc( userdata->userdata_len );
143
        (struct userdata_struct *)SMB_MALLOC( userdata->userdata_len );
144
144
145
  if(new_userdata == NULL)
145
  if(new_userdata == NULL)
146
    return NULL;
146
    return NULL;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_winsserver.c (-3 / +3 lines)
Lines 272-278 Link Here
272
    }
272
    }
273
273
274
    /* Allocate the space for the ip_list. */
274
    /* Allocate the space for the ip_list. */
275
    if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL)
275
    if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips )) == NULL)
276
    {
276
    {
277
      DEBUG(0,("initialise_wins: Malloc fail !\n"));
277
      DEBUG(0,("initialise_wins: Malloc fail !\n"));
278
      return False;
278
      return False;
Lines 1237-1243 Link Here
1237
    return;
1237
    return;
1238
  }
1238
  }
1239
1239
1240
  if((prdata = (char *)malloc( num_ips * 6 )) == NULL)
1240
  if((prdata = (char *)SMB_MALLOC( num_ips * 6 )) == NULL)
1241
  {
1241
  {
1242
    DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n"));
1242
    DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n"));
1243
    return;
1243
    return;
Lines 1309-1315 Link Here
1309
      prdata = rdata;
1309
      prdata = rdata;
1310
    else
1310
    else
1311
    {
1311
    {
1312
      if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL)
1312
      if((prdata = (char *)SMB_MALLOC( namerec->data.num_ips * 6 )) == NULL)
1313
      {
1313
      {
1314
        DEBUG(0,("send_wins_name_query_response: malloc fail !\n"));
1314
        DEBUG(0,("send_wins_name_query_response: malloc fail !\n"));
1315
        return;
1315
        return;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nmbd/nmbd_workgroupdb.c (-1 / +1 lines)
Lines 55-61 Link Here
55
  struct subnet_record *subrec;
55
  struct subnet_record *subrec;
56
  int t = -1;
56
  int t = -1;
57
  
57
  
58
  if((work = (struct work_record *)malloc(sizeof(*work))) == NULL)
58
  if((work = SMB_MALLOC_P(struct work_record)) == NULL)
59
  {
59
  {
60
    DEBUG(0,("create_workgroup: malloc fail !\n"));
60
    DEBUG(0,("create_workgroup: malloc fail !\n"));
61
    return NULL;
61
    return NULL;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nsswitch/wb_client.c (-1 / +1 lines)
Lines 312-318 Link Here
312
		/* Add group to list if necessary */
312
		/* Add group to list if necessary */
313
313
314
		if (!is_member) {
314
		if (!is_member) {
315
			tgr = (gid_t *)Realloc(groups, sizeof(gid_t) * ngroups + 1);
315
			tgr = SMB_REALLOC_ARRAY( groups, gid_t, ngroups + 1 );
316
			
316
			
317
			if (!tgr) {
317
			if (!tgr) {
318
				errno = ENOMEM;
318
				errno = ENOMEM;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nsswitch/winbindd.c (-2 / +1 lines)
Lines 337-344 Link Here
337
	
337
	
338
	/* Create new connection structure */
338
	/* Create new connection structure */
339
	
339
	
340
	if ((state = (struct winbindd_cli_state *) 
340
	if ((state = SMB_MALLOC_P(struct winbindd_cli_state)) == NULL)
341
             malloc(sizeof(*state))) == NULL)
342
		return;
341
		return;
343
	
342
	
344
	ZERO_STRUCTP(state);
343
	ZERO_STRUCTP(state);
(-)samba-2.2.12-pre-CAN-2004-1154/source/nsswitch/winbindd_cache.c (-12 / +12 lines)
Lines 95-101 Link Here
95
95
96
	if (ret) return ret;
96
	if (ret) return ret;
97
	
97
	
98
	ret = smb_xmalloc(sizeof(*ret));
98
	ret = SMB_XMALLOC_P(struct winbind_cache);
99
	ZERO_STRUCTP(ret);
99
	ZERO_STRUCTP(ret);
100
	switch (lp_security()) {
100
	switch (lp_security()) {
101
#ifdef HAVE_ADS
101
#ifdef HAVE_ADS
Lines 179-185 Link Here
179
		smb_panic("centry_string");
179
		smb_panic("centry_string");
180
	}
180
	}
181
181
182
	ret = talloc(mem_ctx, len+1);
182
	ret = TALLOC_ARRAY(mem_ctx, char, len+1);
183
	if (!ret) {
183
	if (!ret) {
184
		smb_panic("centry_string out of memory\n");
184
		smb_panic("centry_string out of memory\n");
185
	}
185
	}
Lines 292-298 Link Here
292
		return NULL;
292
		return NULL;
293
	}
293
	}
294
294
295
	centry = smb_xmalloc(sizeof(*centry));
295
	centry = SMB_XMALLOC_P(struct cache_entry);
296
	centry->data = (uchar *)data.dptr;
296
	centry->data = (uchar *)data.dptr;
297
	centry->len = data.dsize;
297
	centry->len = data.dsize;
298
	centry->ofs = 0;
298
	centry->ofs = 0;
Lines 322-328 Link Here
322
	uint8 *p;
322
	uint8 *p;
323
	if (centry->len - centry->ofs >= len) return;
323
	if (centry->len - centry->ofs >= len) return;
324
	centry->len *= 2;
324
	centry->len *= 2;
325
	p = realloc(centry->data, centry->len);
325
	p = SMB_REALLOC(centry->data, centry->len);
326
	if (!p) {
326
	if (!p) {
327
		DEBUG(0,("out of memory: needed %d bytes in centry_expand\n", centry->len));
327
		DEBUG(0,("out of memory: needed %d bytes in centry_expand\n", centry->len));
328
		smb_panic("out of memory in centry_expand");
328
		smb_panic("out of memory in centry_expand");
Lines 381-390 Link Here
381
381
382
	if (!wcache->tdb) return NULL;
382
	if (!wcache->tdb) return NULL;
383
383
384
	centry = smb_xmalloc(sizeof(*centry));
384
	centry = SMB_XMALLOC_P(struct cache_entry);
385
385
386
	centry->len = 8192; /* reasonable default */
386
	centry->len = 8192; /* reasonable default */
387
	centry->data = smb_xmalloc(centry->len);
387
	centry->data = SMB_XMALLOC_ARRAY(char, centry->len);
388
	centry->ofs = 0;
388
	centry->ofs = 0;
389
	centry->sequence_number = domain->sequence_number;
389
	centry->sequence_number = domain->sequence_number;
390
	centry_put_uint32(centry, NT_STATUS_V(status));
390
	centry_put_uint32(centry, NT_STATUS_V(status));
Lines 494-500 Link Here
494
	
494
	
495
	if (*num_entries == 0) goto do_cached;
495
	if (*num_entries == 0) goto do_cached;
496
496
497
	(*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
497
	(*info) = TALLOC_ARRAY(mem_ctx, WINBIND_USERINFO, *num_entries);
498
	if (! (*info)) smb_panic("query_user_list out of memory");
498
	if (! (*info)) smb_panic("query_user_list out of memory");
499
	for (i=0; i<(*num_entries); i++) {
499
	for (i=0; i<(*num_entries); i++) {
500
		(*info)[i].acct_name = centry_string(centry, mem_ctx);
500
		(*info)[i].acct_name = centry_string(centry, mem_ctx);
Lines 580-586 Link Here
580
	
580
	
581
	if (*num_entries == 0) goto do_cached;
581
	if (*num_entries == 0) goto do_cached;
582
582
583
	(*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
583
	(*info) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_entries);
584
	if (! (*info)) smb_panic("enum_dom_groups out of memory");
584
	if (! (*info)) smb_panic("enum_dom_groups out of memory");
585
	for (i=0; i<(*num_entries); i++) {
585
	for (i=0; i<(*num_entries); i++) {
586
		fstrcpy((*info)[i].acct_name, centry_string(centry, mem_ctx));
586
		fstrcpy((*info)[i].acct_name, centry_string(centry, mem_ctx));
Lines 783-789 Link Here
783
	
783
	
784
	if (*num_groups == 0) goto do_cached;
784
	if (*num_groups == 0) goto do_cached;
785
785
786
	(*user_gids) = talloc(mem_ctx, sizeof(**user_gids) * (*num_groups));
786
	(*user_gids) = TALLOC_ARRAY(mem_ctx, uint32, *num_groups);
787
	if (! (*user_gids)) smb_panic("lookup_usergroups out of memory");
787
	if (! (*user_gids)) smb_panic("lookup_usergroups out of memory");
788
	for (i=0; i<(*num_groups); i++) {
788
	for (i=0; i<(*num_groups); i++) {
789
		(*user_gids)[i] = centry_uint32(centry);
789
		(*user_gids)[i] = centry_uint32(centry);
Lines 841-849 Link Here
841
	
841
	
842
	if (*num_names == 0) goto do_cached;
842
	if (*num_names == 0) goto do_cached;
843
843
844
	(*rid_mem) = talloc(mem_ctx, sizeof(**rid_mem) * (*num_names));
844
	(*rid_mem) = TALLOC_ARRAY(mem_ctx, uint32, *num_names);
845
	(*names) = talloc(mem_ctx, sizeof(**names) * (*num_names));
845
	(*names) = TALLOC_ARRAY(mem_ctx, char *, *num_names);
846
	(*name_types) = talloc(mem_ctx, sizeof(**name_types) * (*num_names));
846
	(*name_types) = TALLOC_ARRAY(mem_ctx, uint32, *num_names);
847
847
848
	if (! (*rid_mem) || ! (*names) || ! (*name_types)) {
848
	if (! (*rid_mem) || ! (*names) || ! (*name_types)) {
849
		smb_panic("lookup_groupmem out of memory");
849
		smb_panic("lookup_groupmem out of memory");
(-)samba-2.2.12-pre-CAN-2004-1154/source/nsswitch/winbindd_cm.c (-9 / +5 lines)
Lines 235-242 Link Here
235
235
236
	/* Create negative lookup cache entry for this domain and controller */
236
	/* Create negative lookup cache entry for this domain and controller */
237
237
238
	if (!(fcc = (struct failed_connection_cache *)
238
	if (!(fcc = SMB_MALLOC_P(struct failed_connection_cache))) {
239
	      malloc(sizeof(struct failed_connection_cache)))) {
240
		DEBUG(0, ("malloc failed in add_failed_connection_entry!\n"));
239
		DEBUG(0, ("malloc failed in add_failed_connection_entry!\n"));
241
		return;
240
		return;
242
	}
241
	}
Lines 396-402 Link Here
396
	}
395
	}
397
	
396
	
398
	if (!conn) {
397
	if (!conn) {
399
		if (!(conn = (struct winbindd_cm_conn *) malloc(sizeof(struct winbindd_cm_conn))))
398
		if (!(conn = SMB_MALLOC_P(struct winbindd_cm_conn)))
400
			return NT_STATUS_NO_MEMORY;
399
			return NT_STATUS_NO_MEMORY;
401
		
400
		
402
		ZERO_STRUCTP(conn);
401
		ZERO_STRUCTP(conn);
Lines 565-572 Link Here
565
			basic_conn = conn;
564
			basic_conn = conn;
566
	}
565
	}
567
	
566
	
568
	if (!(conn = (struct winbindd_cm_conn *)
567
	if (!(conn = SMB_MALLOC_P(struct winbindd_cm_conn)))
569
	      malloc(sizeof(struct winbindd_cm_conn))))
570
		return NULL;
568
		return NULL;
571
	
569
	
572
	ZERO_STRUCTP(conn);
570
	ZERO_STRUCTP(conn);
Lines 641-648 Link Here
641
		return NULL;
639
		return NULL;
642
	}
640
	}
643
641
644
	if (!(conn = (struct winbindd_cm_conn *)
642
	if (!(conn = SMB_MALLOC_P(struct winbindd_cm_conn)))
645
	      malloc(sizeof(struct winbindd_cm_conn))))
646
		return NULL;
643
		return NULL;
647
	
644
	
648
	ZERO_STRUCTP(conn);
645
	ZERO_STRUCTP(conn);
Lines 718-725 Link Here
718
		return NULL;
715
		return NULL;
719
	}
716
	}
720
717
721
	if (!(conn = (struct winbindd_cm_conn *)
718
	if (!(conn = SMB_MALLOC_P(struct winbindd_cm_conn)))
722
	      malloc(sizeof(struct winbindd_cm_conn))))
723
		return NULL;
719
		return NULL;
724
	
720
	
725
	ZERO_STRUCTP(conn);
721
	ZERO_STRUCTP(conn);
(-)samba-2.2.12-pre-CAN-2004-1154/source/nsswitch/winbindd_group.c (-9 / +8 lines)
Lines 151-157 Link Here
151
	/* Allocate buffer */
151
	/* Allocate buffer */
152
152
153
	if (!buf && buf_len != 0) {
153
	if (!buf && buf_len != 0) {
154
		if (!(buf = malloc(buf_len))) {
154
		if (!(buf = SMB_MALLOC(buf_len))) {
155
			DEBUG(1, ("out of memory\n"));
155
			DEBUG(1, ("out of memory\n"));
156
			result = False;
156
			result = False;
157
			goto done;
157
			goto done;
Lines 358-365 Link Here
358
		
358
		
359
		/* Create a state record for this domain */
359
		/* Create a state record for this domain */
360
		
360
		
361
		if ((domain_state = (struct getent_state *)
361
		if ((domain_state = SMB_MALLOC_P(struct getent_state)) == NULL)
362
		     malloc(sizeof(struct getent_state))) == NULL)
363
			return WINBINDD_ERROR;
362
			return WINBINDD_ERROR;
364
		
363
		
365
		ZERO_STRUCTP(domain_state);
364
		ZERO_STRUCTP(domain_state);
Lines 431-437 Link Here
431
	/* Copy entries into return buffer */
430
	/* Copy entries into return buffer */
432
431
433
	if (num_entries) {
432
	if (num_entries) {
434
		name_list = malloc(sizeof(struct acct_info) * num_entries);
433
		name_list = SMB_MALLOC_ARRAY(struct acct_info, num_entries);
435
		memcpy(name_list, sam_grp_entries, 
434
		memcpy(name_list, sam_grp_entries, 
436
		       num_entries * sizeof(struct acct_info));
435
		       num_entries * sizeof(struct acct_info));
437
	}
436
	}
Lines 477-483 Link Here
477
	num_groups = MIN(MAX_GETGRENT_GROUPS, state->request.data.num_entries);
476
	num_groups = MIN(MAX_GETGRENT_GROUPS, state->request.data.num_entries);
478
477
479
	if ((state->response.extra_data = 
478
	if ((state->response.extra_data = 
480
	     malloc(num_groups * sizeof(struct winbindd_gr))) == NULL)
479
	     SMB_MALLOC_ARRAY( struct winbindd_gr, num_groups )) == NULL)
481
		return WINBINDD_ERROR;
480
		return WINBINDD_ERROR;
482
481
483
	state->response.data.num_entries = 0;
482
	state->response.data.num_entries = 0;
Lines 593-599 Link Here
593
592
594
		if (result) {
593
		if (result) {
595
			/* Append to group membership list */
594
			/* Append to group membership list */
596
			new_gr_mem_list = Realloc(
595
			new_gr_mem_list = SMB_REALLOC(
597
				gr_mem_list,
596
				gr_mem_list,
598
				gr_mem_list_len + gr_mem_len);
597
				gr_mem_list_len + gr_mem_len);
599
598
Lines 646-652 Link Here
646
	if (group_list_ndx == 0)
645
	if (group_list_ndx == 0)
647
		goto done;
646
		goto done;
648
647
649
	new_extra_data = Realloc(
648
	new_extra_data = SMB_REALLOC(
650
		state->response.extra_data,
649
		state->response.extra_data,
651
		group_list_ndx * sizeof(struct winbindd_gr) + gr_mem_list_len);
650
		group_list_ndx * sizeof(struct winbindd_gr) + gr_mem_list_len);
652
651
Lines 731-737 Link Here
731
		/* Allocate some memory for extra data.  Note that we limit
730
		/* Allocate some memory for extra data.  Note that we limit
732
		   account names to sizeof(fstring) = 128 characters.  */		
731
		   account names to sizeof(fstring) = 128 characters.  */		
733
732
734
                ted = Realloc(extra_data, sizeof(fstring) * total_entries);
733
                ted = SMB_REALLOC_ARRAY( extra_data, fstring, total_entries );
735
 
734
 
736
		if (!ted) {
735
		if (!ted) {
737
			DEBUG(0,("failed to enlarge buffer!\n"));
736
			DEBUG(0,("failed to enlarge buffer!\n"));
Lines 830-836 Link Here
830
	/* Copy data back to client */
829
	/* Copy data back to client */
831
830
832
	num_gids = 0;
831
	num_gids = 0;
833
	gid_list = malloc(sizeof(gid_t) * num_groups);
832
	gid_list = SMB_MALLOC_ARRAY( gid_t, num_groups );
834
833
835
	if (state->response.extra_data)
834
	if (state->response.extra_data)
836
		goto done;
835
		goto done;
(-)samba-2.2.12-pre-CAN-2004-1154/source/nsswitch/winbindd_misc.c (-3 / +2 lines)
Lines 108-115 Link Here
108
		/* Add domain to list */
108
		/* Add domain to list */
109
109
110
		total_entries++;
110
		total_entries++;
111
		ted = Realloc(extra_data, sizeof(fstring) * 
111
		ted = SMB_REALLOC_ARRAY( extra_data, fstring, total_entries );
112
                              total_entries);
113
112
114
		if (!ted) {
113
		if (!ted) {
115
			DEBUG(0,("winbindd_list_trusted_domains: failed to enlarge buffer!\n"));
114
			DEBUG(0,("winbindd_list_trusted_domains: failed to enlarge buffer!\n"));
Lines 143-149 Link Here
143
142
144
	DEBUG(3, ("[%5d]: show sequence\n", state->pid));
143
	DEBUG(3, ("[%5d]: show sequence\n", state->pid));
145
144
146
	extra_data = strdup("");
145
	extra_data = SMB_STRDUP("");
147
146
148
	/* this makes for a very simple data format, and is easily parsable as well
147
	/* this makes for a very simple data format, and is easily parsable as well
149
	   if that is ever needed */
148
	   if that is ever needed */
(-)samba-2.2.12-pre-CAN-2004-1154/source/nsswitch/winbindd_rpc.c (-8 / +6 lines)
Lines 34-40 Link Here
34
	int maxlen = (str->uni_str_len+1)*4;
34
	int maxlen = (str->uni_str_len+1)*4;
35
	if (!str->buffer)
35
	if (!str->buffer)
36
		return NULL;
36
		return NULL;
37
	s = (char *)talloc(ctx, maxlen); /* convervative */
37
	s = TALLOC_ARRAY(ctx, char *,maxlen); /* convervative */
38
	if (!s)
38
	if (!s)
39
		return NULL;
39
		return NULL;
40
	unistr2_to_unix(s, str, maxlen);
40
	unistr2_to_unix(s, str, maxlen);
Lines 111-118 Link Here
111
		(*num_entries) += count;
111
		(*num_entries) += count;
112
112
113
		/* now map the result into the WINBIND_USERINFO structure */
113
		/* now map the result into the WINBIND_USERINFO structure */
114
		(*info) = talloc_realloc(mem_ctx, *info,
114
		(*info) = TALLOC_REALLOC_ARRAY(mem_ctx, *info, WINBIND_USERINFO,*num_entries);
115
					 (*num_entries)*sizeof(WINBIND_USERINFO));
116
		if (!(*info)) {
115
		if (!(*info)) {
117
			result = NT_STATUS_NO_MEMORY;
116
			result = NT_STATUS_NO_MEMORY;
118
			talloc_destroy(ctx2);
117
			talloc_destroy(ctx2);
Lines 193-200 Link Here
193
			break;
192
			break;
194
		}
193
		}
195
194
196
		(*info) = talloc_realloc(mem_ctx, *info, 
195
		(*info) = TALLOC_REALLOC_ARRAY(mem_ctx, *info, struct acct_info, (*num_entries) + count);
197
					 sizeof(**info) * ((*num_entries) + count));
198
		if (! *info) {
196
		if (! *info) {
199
			talloc_destroy(mem_ctx2);
197
			talloc_destroy(mem_ctx2);
200
			cli_samr_close(hnd->cli, mem_ctx, &dom_pol);
198
			cli_samr_close(hnd->cli, mem_ctx, &dom_pol);
Lines 421-427 Link Here
421
	if (!NT_STATUS_IS_OK(result) || (*num_groups) == 0)
419
	if (!NT_STATUS_IS_OK(result) || (*num_groups) == 0)
422
		goto done;
420
		goto done;
423
421
424
	(*user_gids) = talloc(mem_ctx, sizeof(uint32) * (*num_groups));
422
	(*user_gids) = TALLOC_ARRAY(mem_ctx, uint32, *num_groups);
425
	for (i=0;i<(*num_groups);i++) {
423
	for (i=0;i<(*num_groups);i++) {
426
		(*user_gids)[i] = user_groups[i].g_rid;
424
		(*user_gids)[i] = user_groups[i].g_rid;
427
	}
425
	}
Lines 499-506 Link Here
499
497
500
#define MAX_LOOKUP_RIDS 900
498
#define MAX_LOOKUP_RIDS 900
501
499
502
        *names = talloc_zero(mem_ctx, *num_names * sizeof(char *));
500
        *names = TALLOC_ZERO_ARRAY(mem_ctx, char *, *num_names);
503
        *name_types = talloc_zero(mem_ctx, *num_names * sizeof(uint32));
501
        *name_types = TALLOC_ZERO_ARRAY(mem_ctx, uint32, *num_names);
504
502
505
        for (i = 0; i < *num_names; i += MAX_LOOKUP_RIDS) {
503
        for (i = 0; i < *num_names; i += MAX_LOOKUP_RIDS) {
506
                int num_lookup_rids = MIN(*num_names - i, MAX_LOOKUP_RIDS);
504
                int num_lookup_rids = MIN(*num_names - i, MAX_LOOKUP_RIDS);
(-)samba-2.2.12-pre-CAN-2004-1154/source/nsswitch/winbindd_user.c (-8 / +4 lines)
Lines 291-298 Link Here
291
291
292
		/* Create a state record for this domain */
292
		/* Create a state record for this domain */
293
                
293
                
294
		if ((domain_state = (struct getent_state *)
294
		if ((domain_state = SMB_MALLOC_P(struct getent_state)) == NULL)
295
		     malloc(sizeof(struct getent_state))) == NULL)
296
			return WINBINDD_ERROR;
295
			return WINBINDD_ERROR;
297
                
296
                
298
		ZERO_STRUCTP(domain_state);
297
		ZERO_STRUCTP(domain_state);
Lines 368-377 Link Here
368
	if (num_entries) {
367
	if (num_entries) {
369
		struct getpwent_user *tnl;
368
		struct getpwent_user *tnl;
370
		
369
		
371
		tnl = (struct getpwent_user *)Realloc(name_list, 
370
		tnl = SMB_REALLOC_ARRAY(name_list, struct getpwent_user, ent->num_sam_entries + num_entries );
372
						      sizeof(struct getpwent_user) *
373
						      (ent->num_sam_entries + 
374
						       num_entries));
375
		
371
		
376
		if (!tnl) {
372
		if (!tnl) {
377
			DEBUG(0,("get_sam_user_entries realloc failed.\n"));
373
			DEBUG(0,("get_sam_user_entries realloc failed.\n"));
Lines 438-444 Link Here
438
	num_users = MIN(MAX_GETPWENT_USERS, state->request.data.num_entries);
434
	num_users = MIN(MAX_GETPWENT_USERS, state->request.data.num_entries);
439
	
435
	
440
	if ((state->response.extra_data = 
436
	if ((state->response.extra_data = 
441
	     malloc(num_users * sizeof(struct winbindd_pw))) == NULL)
437
	     SMB_MALLOC_ARRAY(struct winbindd_pw, num_users)) == NULL)
442
		return WINBINDD_ERROR;
438
		return WINBINDD_ERROR;
443
439
444
	memset(state->response.extra_data, 0, num_users * 
440
	memset(state->response.extra_data, 0, num_users * 
Lines 602-608 Link Here
602
598
603
		total_entries += num_entries;
599
		total_entries += num_entries;
604
			
600
			
605
		ted = Realloc(extra_data, sizeof(fstring) * total_entries);
601
		ted = SMB_REALLOC_ARRAY( extra_data, fstring, total_entries );
606
			
602
			
607
		if (!ted) {
603
		if (!ted) {
608
			DEBUG(0,("failed to enlarge buffer!\n"));
604
			DEBUG(0,("failed to enlarge buffer!\n"));
(-)samba-2.2.12-pre-CAN-2004-1154/source/nsswitch/winbindd_util.c (-2 / +1 lines)
Lines 91-98 Link Here
91
        
91
        
92
	/* Create new domain entry */
92
	/* Create new domain entry */
93
93
94
	if ((domain = (struct winbindd_domain *)
94
	if ((domain = SMB_MALLOC_P(struct winbindd_domain)) == NULL)
95
	     malloc(sizeof(*domain))) == NULL)
96
		return NULL;
95
		return NULL;
97
96
98
	/* Fill in fields */
97
	/* Fill in fields */
(-)samba-2.2.12-pre-CAN-2004-1154/source/pam_smbpass/support.c (-1 / +1 lines)
Lines 236-242 Link Here
236
    register char *new = NULL;
236
    register char *new = NULL;
237
237
238
    if (x != NULL) {
238
    if (x != NULL) {
239
        register int i;
239
        register size_t i;
240
240
241
        for (i = 0; x[i]; ++i); /* length of string */
241
        for (i = 0; x[i]; ++i); /* length of string */
242
        if ((new = malloc(++i)) == NULL) {
242
        if ((new = malloc(++i)) == NULL) {
(-)samba-2.2.12-pre-CAN-2004-1154/source/param/loadparm.c (-16 / +13 lines)
Lines 1499-1505 Link Here
1499
	if (!lp_talloc)
1499
	if (!lp_talloc)
1500
		lp_talloc = talloc_init();
1500
		lp_talloc = talloc_init();
1501
1501
1502
	ret = (char *)talloc(lp_talloc, len + 100);	/* leave room for substitution */
1502
	ret = TALLOC_ARRAY(lp_talloc, char, len + 100);	/* leave room for substitution */
1503
1503
1504
	if (!ret)
1504
	if (!ret)
1505
		return NULL;
1505
		return NULL;
Lines 1918-1934 Link Here
1918
			memcpy(oldservices, ServicePtrs, sizeof(service *) * iNumServices);
1918
			memcpy(oldservices, ServicePtrs, sizeof(service *) * iNumServices);
1919
#endif
1919
#endif
1920
1920
1921
		tsp = (service **) Realloc(ServicePtrs,
1921
		tsp = SMB_REALLOC_ARRAY( ServicePtrs, service *, num_to_alloc );
1922
						sizeof(service *) *
1923
						num_to_alloc);
1924
 
1922
 
1925
		if (!tsp) {
1923
		if (!tsp) {
1926
			DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
1924
			DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
1927
			return (-1);
1925
			return (-1);
1928
		} else {
1926
		} else {
1929
			ServicePtrs = tsp;
1927
			ServicePtrs = tsp;
1930
			ServicePtrs[iNumServices] =
1928
			ServicePtrs[iNumServices] = SMB_MALLOC_P(service);
1931
				(service *) malloc(sizeof(service));
1932
        }
1929
        }
1933
1930
1934
#ifdef __INSURE__
1931
#ifdef __INSURE__
Lines 2270-2285 Link Here
2270
	}
2267
	}
2271
 
2268
 
2272
	if (!f) {
2269
	if (!f) {
2273
		f = (struct file_lists *)malloc(sizeof(file_lists[0]));
2270
		f = SMB_MALLOC_P(struct file_lists);
2274
		if (!f)
2271
		if (!f)
2275
			return;
2272
			return;
2276
		f->next = file_lists;
2273
		f->next = file_lists;
2277
		f->name = strdup(fname);
2274
		f->name = SMB_STRDUP(fname);
2278
		if (!f->name) {
2275
		if (!f->name) {
2279
			SAFE_FREE(f);
2276
			SAFE_FREE(f);
2280
			return;
2277
			return;
2281
		}
2278
		}
2282
		f->subfname = strdup(subfname);
2279
		f->subfname = SMB_STRDUP(subfname);
2283
		if (!f->subfname) {
2280
		if (!f->subfname) {
2284
			SAFE_FREE(f);
2281
			SAFE_FREE(f);
2285
			return;
2282
			return;
Lines 2317-2323 Link Here
2317
			DEBUGADD(6, ("file %s modified: %s\n", n2, ctime(&mod_time)));
2314
			DEBUGADD(6, ("file %s modified: %s\n", n2, ctime(&mod_time)));
2318
			f->modtime = mod_time;
2315
			f->modtime = mod_time;
2319
			SAFE_FREE(f->subfname);
2316
			SAFE_FREE(f->subfname);
2320
			f->subfname = strdup(n2);
2317
			f->subfname = SMB_STRDUP(n2);
2321
			return (True);
2318
			return (True);
2322
		}
2319
		}
2323
		f = f->next;
2320
		f = f->next;
Lines 2375-2381 Link Here
2375
		if (line[len - 1] == '\n')
2372
		if (line[len - 1] == '\n')
2376
			line[--len] = '\0';
2373
			line[--len] = '\0';
2377
2374
2378
		if ((varval = malloc(len + 1)) == NULL)
2375
		if ((varval = SMB_MALLOC(len + 1)) == NULL)
2379
		{
2376
		{
2380
			DEBUG(0, ("source_env: Not enough memory!\n"));
2377
			DEBUG(0, ("source_env: Not enough memory!\n"));
2381
			return (False);
2378
			return (False);
Lines 2495-2501 Link Here
2495
	 */
2492
	 */
2496
	string_set(ptr, pszParmValue);
2493
	string_set(ptr, pszParmValue);
2497
	strupper(*ptr);
2494
	strupper(*ptr);
2498
	saved_character_set = strdup(*ptr);
2495
	saved_character_set = SMB_STRDUP(*ptr);
2499
	interpret_character_set(*ptr, lp_client_code_page());
2496
	interpret_character_set(*ptr, lp_client_code_page());
2500
	return (True);
2497
	return (True);
2501
}
2498
}
Lines 2732-2738 Link Here
2732
{
2729
{
2733
	int i;
2730
	int i;
2734
	SAFE_FREE(pservice->copymap);
2731
	SAFE_FREE(pservice->copymap);
2735
	pservice->copymap = (BOOL *)malloc(sizeof(BOOL) * NUMPARAMETERS);
2732
	pservice->copymap = SMB_MALLOC_ARRAY(BOOL, NUMPARAMETERS);
2736
	if (!pservice->copymap)
2733
	if (!pservice->copymap)
2737
		DEBUG(0,
2734
		DEBUG(0,
2738
		      ("Couldn't allocate copymap!! (size %d)\n",
2735
		      ("Couldn't allocate copymap!! (size %d)\n",
Lines 3302-3308 Link Here
3302
	if (!str)
3299
	if (!str)
3303
		return;
3300
		return;
3304
3301
3305
	s = strdup(str);
3302
	s = SMB_STRDUP(str);
3306
	if (!s)
3303
	if (!s)
3307
		return;
3304
		return;
3308
3305
Lines 3396-3407 Link Here
3396
			case P_STRING:
3393
			case P_STRING:
3397
			case P_USTRING:
3394
			case P_USTRING:
3398
				parm_table[i].def.svalue =
3395
				parm_table[i].def.svalue =
3399
					strdup(*(char **)parm_table[i].ptr);
3396
					SMB_STRDUP(*(char **)parm_table[i].ptr);
3400
				break;
3397
				break;
3401
			case P_GSTRING:
3398
			case P_GSTRING:
3402
			case P_UGSTRING:
3399
			case P_UGSTRING:
3403
				parm_table[i].def.svalue =
3400
				parm_table[i].def.svalue =
3404
					strdup((char *)parm_table[i].ptr);
3401
					SMB_STRDUP((char *)parm_table[i].ptr);
3405
				break;
3402
				break;
3406
			case P_BOOL:
3403
			case P_BOOL:
3407
			case P_BOOLREV:
3404
			case P_BOOLREV:
(-)samba-2.2.12-pre-CAN-2004-1154/source/param/params.c (-5 / +5 lines)
Lines 252-258 Link Here
252
      {
252
      {
253
      char *tb;
253
      char *tb;
254
254
255
      tb = Realloc( bufr, bSize +BUFR_INC );
255
      tb = SMB_REALLOC( bufr, bSize +BUFR_INC );
256
      if( NULL == tb )
256
      if( NULL == tb )
257
        {
257
        {
258
        DEBUG(0, ("%s Memory re-allocation failure.", func) );
258
        DEBUG(0, ("%s Memory re-allocation failure.", func) );
Lines 349-355 Link Here
349
      {
349
      {
350
      char *tb;
350
      char *tb;
351
 
351
 
352
      tb = Realloc( bufr, bSize + BUFR_INC );
352
      tb = SMB_REALLOC( bufr, bSize + BUFR_INC );
353
      if( NULL == tb )
353
      if( NULL == tb )
354
        {
354
        {
355
        DEBUG(0, ("%s Memory re-allocation failure.", func) );
355
        DEBUG(0, ("%s Memory re-allocation failure.", func) );
Lines 416-422 Link Here
416
    if( i > (bSize - 2) )       /* Make sure there's enough room. */
416
    if( i > (bSize - 2) )       /* Make sure there's enough room. */
417
      {
417
      {
418
      bSize += BUFR_INC;
418
      bSize += BUFR_INC;
419
      bufr   = Realloc( bufr, bSize );
419
      bufr   = SMB_REALLOC( bufr, bSize );
420
      if( NULL == bufr )
420
      if( NULL == bufr )
421
        {
421
        {
422
        DEBUG(0, ("%s Memory re-allocation failure.", func) );
422
        DEBUG(0, ("%s Memory re-allocation failure.", func) );
Lines 532-538 Link Here
532
  int lvl = in_client?1:0;
532
  int lvl = in_client?1:0;
533
  myFILE *ret;
533
  myFILE *ret;
534
534
535
  ret = (myFILE *)malloc(sizeof(*ret));
535
  ret = SMB_MALLOC_P(myFILE);
536
  if (!ret) return NULL;
536
  if (!ret) return NULL;
537
537
538
  ret->buf = file_load(FileName, &ret->size);
538
  ret->buf = file_load(FileName, &ret->size);
Lines 583-589 Link Here
583
  else                                        /* If we don't have a buffer   */
583
  else                                        /* If we don't have a buffer   */
584
    {                                         /* allocate one, then parse,   */
584
    {                                         /* allocate one, then parse,   */
585
    bSize = BUFR_INC;                         /* then free.                  */
585
    bSize = BUFR_INC;                         /* then free.                  */
586
    bufr = (char *)malloc( bSize );
586
    bufr = (char *)SMB_MALLOC( bSize );
587
    if( NULL == bufr )
587
    if( NULL == bufr )
588
      {
588
      {
589
      DEBUG(0,("%s memory allocation failure.\n", func));
589
      DEBUG(0,("%s memory allocation failure.\n", func));
(-)samba-2.2.12-pre-CAN-2004-1154/source/passdb/pampass.c (-6 / +6 lines)
Lines 57-63 Link Here
57
/*
57
/*
58
 *  Macros to help make life easy
58
 *  Macros to help make life easy
59
 */
59
 */
60
#define COPY_STRING(s) (s) ? strdup(s) : NULL
60
#define COPY_STRING(s) (s) ? SMB_STRDUP(s) : NULL
61
61
62
/*******************************************************************
62
/*******************************************************************
63
 PAM error handler.
63
 PAM error handler.
Lines 126-132 Link Here
126
		return PAM_CONV_ERR;
126
		return PAM_CONV_ERR;
127
	}
127
	}
128
128
129
	reply = malloc(sizeof(struct pam_response) * num_msg);
129
	reply = SMB_MALLOC_ARRAY( struct pam_response, num_msg );
130
	if (!reply)
130
	if (!reply)
131
		return PAM_CONV_ERR;
131
		return PAM_CONV_ERR;
132
132
Lines 207-213 Link Here
207
	struct chat_struct *tmp;
207
	struct chat_struct *tmp;
208
208
209
	while (1) {
209
	while (1) {
210
		t = (struct chat_struct *)malloc(sizeof(*t));
210
		t = SMB_MALLOC_P(struct chat_struct);
211
		if (!t) {
211
		if (!t) {
212
			DEBUG(0,("make_pw_chat: malloc failed!\n"));
212
			DEBUG(0,("make_pw_chat: malloc failed!\n"));
213
			return NULL;
213
			return NULL;
Lines 286-292 Link Here
286
		return PAM_CONV_ERR;
286
		return PAM_CONV_ERR;
287
	}
287
	}
288
288
289
	reply = malloc(sizeof(struct pam_response) * num_msg);
289
	reply = SMB_MALLOC_ARRAY( struct pam_response, num_msg );
290
	if (!reply) {
290
	if (!reply) {
291
		DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
291
		DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
292
		free_pw_chat(pw_chat);
292
		free_pw_chat(pw_chat);
Lines 402-409 Link Here
402
static struct pam_conv *smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr, const char *user,
402
static struct pam_conv *smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr, const char *user,
403
					const char *passwd, const char *newpass)
403
					const char *passwd, const char *newpass)
404
{
404
{
405
	struct pam_conv *pconv = (struct pam_conv *)malloc(sizeof(struct pam_conv));
405
	struct pam_conv *pconv = SMB_MALLOC_P(struct pam_conv);
406
	struct smb_pam_userdata *udp = (struct smb_pam_userdata *)malloc(sizeof(struct smb_pam_userdata));
406
	struct smb_pam_userdata *udp = SMB_MALLOC_P(struct smb_pam_userdata);
407
407
408
	if (pconv == NULL || udp == NULL) {
408
	if (pconv == NULL || udp == NULL) {
409
		SAFE_FREE(pconv);
409
		SAFE_FREE(pconv);
(-)samba-2.2.12-pre-CAN-2004-1154/source/passdb/passdb.c (-3 / +3 lines)
Lines 110-116 Link Here
110
		return False;
110
		return False;
111
	}
111
	}
112
	
112
	
113
	*user=(SAM_ACCOUNT *)malloc(sizeof(SAM_ACCOUNT));
113
	*user=SMB_MALLOC_P(SAM_ACCOUNT);
114
	
114
	
115
	if (*user==NULL) {
115
	if (*user==NULL) {
116
		DEBUG(0,("pdb_init_sam: error while allocating memory\n"));
116
		DEBUG(0,("pdb_init_sam: error while allocating memory\n"));
Lines 1620-1626 Link Here
1620
	if (sampass->nt_pw!=NULL)
1620
	if (sampass->nt_pw!=NULL)
1621
		DEBUG(4,("pdb_set_nt_passwd: NT hash non NULL overwritting ?\n"));
1621
		DEBUG(4,("pdb_set_nt_passwd: NT hash non NULL overwritting ?\n"));
1622
	else
1622
	else
1623
		sampass->nt_pw=(unsigned char *)malloc(sizeof(unsigned char)*16);
1623
		sampass->nt_pw=SMB_MALLOC_ARRAY( unsigned char, 16 );
1624
	
1624
	
1625
	if (sampass->nt_pw==NULL)
1625
	if (sampass->nt_pw==NULL)
1626
		return False;
1626
		return False;
Lines 1651-1657 Link Here
1651
	if (sampass->lm_pw!=NULL)
1651
	if (sampass->lm_pw!=NULL)
1652
		DEBUG(4,("pdb_set_lanman_passwd: LM hash non NULL overwritting ?\n"));
1652
		DEBUG(4,("pdb_set_lanman_passwd: LM hash non NULL overwritting ?\n"));
1653
	else
1653
	else
1654
		sampass->lm_pw=(unsigned char *)malloc(sizeof(unsigned char)*16);
1654
		sampass->lm_pw=SMB_MALLOC_ARRAY( unsigned char, 16 );
1655
	
1655
	
1656
	if (sampass->lm_pw==NULL)
1656
	if (sampass->lm_pw==NULL)
1657
		return False;
1657
		return False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/passdb/pdb_ldap.c (-3 / +2 lines)
Lines 480-486 Link Here
480
480
481
	if (mods[i] == NULL)
481
	if (mods[i] == NULL)
482
	{
482
	{
483
		mods = (LDAPMod **) Realloc (mods, (i + 2) * sizeof (LDAPMod *));
483
		mods = SMB_REALLOC_ARRAY ( mods, LDAPMod *, i + 2 );
484
		if (mods == NULL)
484
		if (mods == NULL)
485
		{
485
		{
486
			DEBUG(0, ("make_a_mod: out of memory!\n"));
486
			DEBUG(0, ("make_a_mod: out of memory!\n"));
Lines 504-511 Link Here
504
		if (mods[i]->mod_values != NULL) {
504
		if (mods[i]->mod_values != NULL) {
505
			for (; mods[i]->mod_values[j] != NULL; j++);
505
			for (; mods[i]->mod_values[j] != NULL; j++);
506
		}
506
		}
507
		mods[i]->mod_values = (char **)Realloc(mods[i]->mod_values,
507
		mods[i]->mod_values = SMB_REALLOC_ARRAY( mods[i]->mod_values, char *, j + 2 );
508
					       (j + 2) * sizeof (char *));
509
					       
508
					       
510
		if (mods[i]->mod_values == NULL) {
509
		if (mods[i]->mod_values == NULL) {
511
			DEBUG (0, ("make_a_mod: Memory allocation failure!\n"));
510
			DEBUG (0, ("make_a_mod: Memory allocation failure!\n"));
(-)samba-2.2.12-pre-CAN-2004-1154/source/passdb/pdb_smbpasswd.c (-1 / +1 lines)
Lines 501-507 Link Here
501
501
502
  new_entry_length = strlen(newpwd->smb_name) + 1 + 15 + 1 + 32 + 1 + 32 + 1 + NEW_PW_FORMAT_SPACE_PADDED_LEN + 1 + 13 + 2;
502
  new_entry_length = strlen(newpwd->smb_name) + 1 + 15 + 1 + 32 + 1 + 32 + 1 + NEW_PW_FORMAT_SPACE_PADDED_LEN + 1 + 13 + 2;
503
503
504
  if((new_entry = (char *)malloc( new_entry_length )) == NULL) {
504
  if((new_entry = (char *)SMB_MALLOC( new_entry_length )) == NULL) {
505
    DEBUG(0, ("format_new_smbpasswd_entry: Malloc failed adding entry for user %s.\n", newpwd->smb_name ));
505
    DEBUG(0, ("format_new_smbpasswd_entry: Malloc failed adding entry for user %s.\n", newpwd->smb_name ));
506
    return NULL;
506
    return NULL;
507
  }
507
  }
(-)samba-2.2.12-pre-CAN-2004-1154/source/printing/load.c (-1 / +1 lines)
Lines 41-47 Link Here
41
{
41
{
42
	char *p;
42
	char *p;
43
	int printers;
43
	int printers;
44
	char *str = strdup(lp_auto_services());
44
	char *str = SMB_STRDUP(lp_auto_services());
45
45
46
	if (!str) return;
46
	if (!str) return;
47
47
(-)samba-2.2.12-pre-CAN-2004-1154/source/printing/nt_printing.c (-18 / +17 lines)
Lines 448-454 Link Here
448
		SAFE_FREE(dbuf.dptr);
448
		SAFE_FREE(dbuf.dptr);
449
		if (ret != dbuf.dsize) continue;
449
		if (ret != dbuf.dsize) continue;
450
450
451
		tl = Realloc(*list, sizeof(nt_forms_struct)*(n+1));
451
		tl = SMB_REALLOC_ARRAY( *list, nt_forms_struct, n+1 );
452
		if (!tl) {
452
		if (!tl) {
453
			DEBUG(0,("get_ntforms: Realloc fail.\n"));
453
			DEBUG(0,("get_ntforms: Realloc fail.\n"));
454
			return 0;
454
			return 0;
Lines 519-525 Link Here
519
	}
519
	}
520
520
521
	if (update==False) {
521
	if (update==False) {
522
		if((tl=Realloc(*list, (n+1)*sizeof(nt_forms_struct))) == NULL) {
522
		if((tl=SMB_REALLOC_ARRAY( *list, nt_forms_struct, n+1 )) == NULL) {
523
			DEBUG(0,("add_a_form: failed to enlarge forms list!\n"));
523
			DEBUG(0,("add_a_form: failed to enlarge forms list!\n"));
524
			return False;
524
			return False;
525
		}
525
		}
Lines 627-633 Link Here
627
	     newkey = tdb_nextkey(tdb_drivers, kbuf), safe_free(kbuf.dptr), kbuf=newkey) {
627
	     newkey = tdb_nextkey(tdb_drivers, kbuf), safe_free(kbuf.dptr), kbuf=newkey) {
628
		if (strncmp(kbuf.dptr, key, strlen(key)) != 0) continue;
628
		if (strncmp(kbuf.dptr, key, strlen(key)) != 0) continue;
629
		
629
		
630
		if((fl = Realloc(*list, sizeof(fstring)*(total+1))) == NULL) {
630
		if((fl = SMB_REALLOC_ARRAY( *list, fstring, total+1)) == NULL) {
631
			DEBUG(0,("get_ntdrivers: failed to enlarge list!\n"));
631
			DEBUG(0,("get_ntdrivers: failed to enlarge list!\n"));
632
			return -1;
632
			return -1;
633
		}
633
		}
Lines 704-710 Link Here
704
	char    *buf;
704
	char    *buf;
705
	ssize_t byte_count;
705
	ssize_t byte_count;
706
706
707
	if ((buf=malloc(PE_HEADER_SIZE)) == NULL) {
707
	if ((buf=SMB_MALLOC(PE_HEADER_SIZE)) == NULL) {
708
		DEBUG(0,("get_file_version: PE file [%s] PE Header malloc failed bytes = %d\n",
708
		DEBUG(0,("get_file_version: PE file [%s] PE Header malloc failed bytes = %d\n",
709
				fname, PE_HEADER_SIZE));
709
				fname, PE_HEADER_SIZE));
710
		goto error_exit;
710
		goto error_exit;
Lines 757-763 Link Here
757
		num_sections        = SVAL(buf,PE_HEADER_NUMBER_OF_SECTIONS);
757
		num_sections        = SVAL(buf,PE_HEADER_NUMBER_OF_SECTIONS);
758
		section_table_bytes = num_sections * PE_HEADER_SECT_HEADER_SIZE;
758
		section_table_bytes = num_sections * PE_HEADER_SECT_HEADER_SIZE;
759
		SAFE_FREE(buf);
759
		SAFE_FREE(buf);
760
		if ((buf=malloc(section_table_bytes)) == NULL) {
760
		if ((buf=SMB_MALLOC(section_table_bytes)) == NULL) {
761
			DEBUG(0,("get_file_version: PE file [%s] section table malloc failed bytes = %d\n",
761
			DEBUG(0,("get_file_version: PE file [%s] section table malloc failed bytes = %d\n",
762
					fname, section_table_bytes));
762
					fname, section_table_bytes));
763
			goto error_exit;
763
			goto error_exit;
Lines 778-784 Link Here
778
				int section_bytes = IVAL(buf,sec_offset+PE_HEADER_SECT_SIZE_DATA_OFFSET);
778
				int section_bytes = IVAL(buf,sec_offset+PE_HEADER_SECT_SIZE_DATA_OFFSET);
779
779
780
				SAFE_FREE(buf);
780
				SAFE_FREE(buf);
781
				if ((buf=malloc(section_bytes)) == NULL) {
781
				if ((buf=SMB_MALLOC(section_bytes)) == NULL) {
782
					DEBUG(0,("get_file_version: PE file [%s] version malloc failed bytes = %d\n",
782
					DEBUG(0,("get_file_version: PE file [%s] version malloc failed bytes = %d\n",
783
							fname, section_bytes));
783
							fname, section_bytes));
784
					goto error_exit;
784
					goto error_exit;
Lines 835-841 Link Here
835
835
836
		/* Allocate a bit more space to speed up things */
836
		/* Allocate a bit more space to speed up things */
837
		SAFE_FREE(buf);
837
		SAFE_FREE(buf);
838
		if ((buf=malloc(VS_NE_BUF_SIZE)) == NULL) {
838
		if ((buf=SMB_MALLOC(VS_NE_BUF_SIZE)) == NULL) {
839
			DEBUG(0,("get_file_version: NE file [%s] malloc failed bytes  = %d\n",
839
			DEBUG(0,("get_file_version: NE file [%s] malloc failed bytes  = %d\n",
840
					fname, PE_HEADER_SIZE));
840
					fname, PE_HEADER_SIZE));
841
			goto error_exit;
841
			goto error_exit;
Lines 1679-1685 Link Here
1679
	if (len != buflen) {
1679
	if (len != buflen) {
1680
		char *tb;
1680
		char *tb;
1681
1681
1682
		tb = (char *)Realloc(buf, len);
1682
		tb = (char *)SMB_REALLOC(buf, len);
1683
		if (!tb) {
1683
		if (!tb) {
1684
			DEBUG(0,("add_a_printer_driver_3: failed to enlarge buffer\n!"));
1684
			DEBUG(0,("add_a_printer_driver_3: failed to enlarge buffer\n!"));
1685
			ret = -1;
1685
			ret = -1;
Lines 1744-1750 Link Here
1744
	fstrcpy(info.configfile, "");
1744
	fstrcpy(info.configfile, "");
1745
	fstrcpy(info.helpfile, "");
1745
	fstrcpy(info.helpfile, "");
1746
1746
1747
	if ((info.dependentfiles=(fstring *)malloc(2*sizeof(fstring))) == NULL)
1747
	if ((info.dependentfiles=SMB_MALLOC_ARRAY( fstring, 2 )) == NULL)
1748
		return WERR_NOMEM;
1748
		return WERR_NOMEM;
1749
1749
1750
	memset(info.dependentfiles, '\0', 2*sizeof(fstring));
1750
	memset(info.dependentfiles, '\0', 2*sizeof(fstring));
Lines 1796-1803 Link Here
1796
	while (len < dbuf.dsize) {
1796
	while (len < dbuf.dsize) {
1797
		fstring *tddfs;
1797
		fstring *tddfs;
1798
1798
1799
		tddfs = (fstring *)Realloc(driver.dependentfiles,
1799
		tddfs = (fstring *)SMB_REALLOC_ARRAY( driver.dependentfiles, fstring, i+2);
1800
							 sizeof(fstring)*(i+2));
1801
		if (tddfs == NULL) {
1800
		if (tddfs == NULL) {
1802
			DEBUG(0,("get_a_printer_driver_3: failed to enlarge buffer!\n"));
1801
			DEBUG(0,("get_a_printer_driver_3: failed to enlarge buffer!\n"));
1803
			break;
1802
			break;
Lines 2111-2117 Link Here
2111
	if (buflen != len) {
2110
	if (buflen != len) {
2112
		char *tb;
2111
		char *tb;
2113
2112
2114
		tb = (char *)Realloc(buf, len);
2113
		tb = (char *)SMB_REALLOC(buf, len);
2115
		if (!tb) {
2114
		if (!tb) {
2116
			DEBUG(0,("update_a_printer_2: failed to enlarge buffer!\n"));
2115
			DEBUG(0,("update_a_printer_2: failed to enlarge buffer!\n"));
2117
			ret = WERR_NOMEM;
2116
			ret = WERR_NOMEM;
Lines 2237-2243 Link Here
2237
{
2236
{
2238
2237
2239
	char adevice[MAXDEVICENAME+1];
2238
	char adevice[MAXDEVICENAME+1];
2240
	NT_DEVICEMODE *nt_devmode = (NT_DEVICEMODE *)malloc(sizeof(NT_DEVICEMODE));
2239
	NT_DEVICEMODE *nt_devmode = SMB_MALLOC_P(NT_DEVICEMODE);
2241
2240
2242
	if (nt_devmode == NULL) {
2241
	if (nt_devmode == NULL) {
2243
		DEBUG(0,("construct_nt_devicemode: malloc fail.\n"));
2242
		DEBUG(0,("construct_nt_devicemode: malloc fail.\n"));
Lines 3070-3076 Link Here
3070
	if (buflen != len) {
3069
	if (buflen != len) {
3071
		char *tb;
3070
		char *tb;
3072
3071
3073
		tb = (char *)Realloc(buf, len);
3072
		tb = (char *)SMB_REALLOC(buf, len);
3074
		if (!tb) {
3073
		if (!tb) {
3075
			DEBUG(0, ("update_driver_init_2: failed to enlarge buffer!\n"));
3074
			DEBUG(0, ("update_driver_init_2: failed to enlarge buffer!\n"));
3076
			ret = -1;
3075
			ret = -1;
Lines 3196-3202 Link Here
3196
		if ((ctx = talloc_init()) == NULL)
3195
		if ((ctx = talloc_init()) == NULL)
3197
			return WERR_NOMEM;
3196
			return WERR_NOMEM;
3198
3197
3199
		if ((nt_devmode = (NT_DEVICEMODE*)malloc(sizeof(NT_DEVICEMODE))) == NULL) {
3198
		if ((nt_devmode = SMB_MALLOC_P(NT_DEVICEMODE)) == NULL) {
3200
			status = WERR_NOMEM;
3199
			status = WERR_NOMEM;
3201
			goto done;
3200
			goto done;
3202
		}
3201
		}
Lines 3293-3299 Link Here
3293
	{
3292
	{
3294
		case 2:
3293
		case 2:
3295
		{
3294
		{
3296
			if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) {
3295
			if ((printer = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL)) == NULL) {
3297
				DEBUG(0,("get_a_printer: malloc fail.\n"));
3296
				DEBUG(0,("get_a_printer: malloc fail.\n"));
3298
				return WERR_NOMEM;
3297
				return WERR_NOMEM;
3299
			}
3298
			}
Lines 3598-3604 Link Here
3598
	/* exited because it exist */
3597
	/* exited because it exist */
3599
	*type=param->type;		
3598
	*type=param->type;		
3600
	StrnCpy(value, param->value, sizeof(fstring)-1);
3599
	StrnCpy(value, param->value, sizeof(fstring)-1);
3601
	*data=(uint8 *)malloc(param->data_len*sizeof(uint8));
3600
	*data= SMB_MALLOC_ARRAY( uint8, param->data_len );
3602
	if(*data == NULL)
3601
	if(*data == NULL)
3603
		return False;
3602
		return False;
3604
	ZERO_STRUCTP(*data);
3603
	ZERO_STRUCTP(*data);
Lines 3638-3644 Link Here
3638
		/* exited because it exist */
3637
		/* exited because it exist */
3639
		*type=param->type;	
3638
		*type=param->type;	
3640
		
3639
		
3641
		*data=(uint8 *)malloc(param->data_len*sizeof(uint8));
3640
		*data= SMB_MALLOC_ARRAY( uint8, param->data_len );
3642
		if(*data == NULL)
3641
		if(*data == NULL)
3643
			return False;
3642
			return False;
3644
		memcpy(*data, param->data, param->data_len);
3643
		memcpy(*data, param->data, param->data_len);
(-)samba-2.2.12-pre-CAN-2004-1154/source/printing/print_cups.c (-1 / +1 lines)
Lines 920-926 Link Here
920
		{
920
		{
921
			qalloc += 16;
921
			qalloc += 16;
922
922
923
			temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
923
			temp = SMB_REALLOC_ARRAY( queue, print_queue_struct, qalloc );
924
924
925
			if (temp == NULL)
925
			if (temp == NULL)
926
			{
926
			{
(-)samba-2.2.12-pre-CAN-2004-1154/source/printing/print_generic.c (-1 / +1 lines)
Lines 218-224 Link Here
218
	qcount = 0;
218
	qcount = 0;
219
	ZERO_STRUCTP(status);
219
	ZERO_STRUCTP(status);
220
	if (numlines)
220
	if (numlines)
221
		queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(numlines+1));
221
		queue = SMB_MALLOC_ARRAY( print_queue_struct, numlines+1 );
222
222
223
	if (queue) {
223
	if (queue) {
224
		for (i=0; i<numlines; i++) {
224
		for (i=0; i<numlines; i++) {
(-)samba-2.2.12-pre-CAN-2004-1154/source/printing/print_svid.c (-2 / +2 lines)
Lines 89-97 Link Here
89
			*tmp = '\0';
89
			*tmp = '\0';
90
		
90
		
91
		/* add it to the cache */
91
		/* add it to the cache */
92
		if ((ptmp = malloc(sizeof (*ptmp))) != NULL) {
92
		if ((ptmp = SMB_MALLOC_P(printer_t)) != NULL) {
93
			ZERO_STRUCTP(ptmp);
93
			ZERO_STRUCTP(ptmp);
94
			if((ptmp->name = strdup(name)) == NULL)
94
			if((ptmp->name = SMB_STRDUP(name)) == NULL)
95
				DEBUG(0,("populate_printers: malloc fail in strdup !\n"));
95
				DEBUG(0,("populate_printers: malloc fail in strdup !\n"));
96
			ptmp->next = printers;
96
			ptmp->next = printers;
97
			printers = ptmp;
97
			printers = ptmp;
(-)samba-2.2.12-pre-CAN-2004-1154/source/printing/printing.c (-2 / +1 lines)
Lines 1313-1320 Link Here
1313
		return 0;
1313
		return 0;
1314
1314
1315
	/* Allocate the queue size. */
1315
	/* Allocate the queue size. */
1316
	if ((tstruct.queue = (print_queue_struct *)
1316
	if ((tstruct.queue = SMB_MALLOC_ARRAY( print_queue_struct, tsc.count )) == NULL)
1317
	     malloc(sizeof(print_queue_struct)*tsc.count)) == NULL)
1318
		return 0;
1317
		return 0;
1319
1318
1320
	/*
1319
	/*
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_client/cli_spoolss_notify.c (-1 / +1 lines)
Lines 328-334 Link Here
328
		{
328
		{
329
			DEBUG(10,("build_notify_data: %s set on [%s][%d]\n", msg_table[i].name,
329
			DEBUG(10,("build_notify_data: %s set on [%s][%d]\n", msg_table[i].name,
330
				printer->info_2->printername, idx));
330
				printer->info_2->printername, idx));
331
			if ((data=Realloc(*notify_data, (idx+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
331
			if ((data=SMB_REALLOC_ARRAY( *notify_data, SPOOL_NOTIFY_INFO_DATA, idx+1)) == NULL) {
332
				DEBUG(0,("build_notify_data: Realloc() failed with size [%d]!\n",
332
				DEBUG(0,("build_notify_data: Realloc() failed with size [%d]!\n",
333
					(idx+1)*sizeof(SPOOL_NOTIFY_INFO_DATA)));
333
					(idx+1)*sizeof(SPOOL_NOTIFY_INFO_DATA)));
334
				return -1;
334
				return -1;
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_parse/parse_dfs.c (-4 / +4 lines)
Lines 371-377 Link Here
371
		depth++;
371
		depth++;
372
		/* should depend on whether marshalling or unmarshalling! */
372
		/* should depend on whether marshalling or unmarshalling! */
373
		if(UNMARSHALLING(ps)) {
373
		if(UNMARSHALLING(ps)) {
374
			ctr->dfs.info1 = (DFS_INFO_1 *)prs_alloc_mem(ps, sizeof(DFS_INFO_1)*num_entries);
374
			ctr->dfs.info1 = PRS_ALLOC_MEM( ps, DFS_INFO_1, num_entries );
375
			if (!ctr->dfs.info1)
375
			if (!ctr->dfs.info1)
376
				return False;
376
				return False;
377
		}
377
		}
Lines 391-397 Link Here
391
	case 2:
391
	case 2:
392
		depth++;
392
		depth++;
393
		if(UNMARSHALLING(ps)) {
393
		if(UNMARSHALLING(ps)) {
394
			ctr->dfs.info2 = (DFS_INFO_2 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_2));
394
			ctr->dfs.info2 = PRS_ALLOC_MEM( ps, DFS_INFO_2, num_entries );
395
			if (!ctr->dfs.info2)
395
			if (!ctr->dfs.info2)
396
				return False;
396
				return False;
397
		}
397
		}
Lines 421-427 Link Here
421
	case 3:
421
	case 3:
422
		depth++;
422
		depth++;
423
		if(UNMARSHALLING(ps)) {
423
		if(UNMARSHALLING(ps)) {
424
			ctr->dfs.info3 = (DFS_INFO_3 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_3));
424
			ctr->dfs.info3 = PRS_ALLOC_MEM(ps, DFS_INFO_3, num_entries );
425
			if (!ctr->dfs.info3)
425
			if (!ctr->dfs.info3)
426
				return False;
426
				return False;
427
		}
427
		}
Lines 514-520 Link Here
514
	depth++;
514
	depth++;
515
515
516
	if(UNMARSHALLING(ps)) {
516
	if(UNMARSHALLING(ps)) {
517
		info3->storages = (DFS_STORAGE_INFO *)prs_alloc_mem(ps, info3->num_storage_infos*sizeof(DFS_STORAGE_INFO));
517
		info3->storages = PRS_ALLOC_MEM( ps, DFS_STORAGE_INFO, info3->num_storage_infos );
518
		if (!info3->storages)
518
		if (!info3->storages)
519
			return False;
519
			return False;
520
	}
520
	}
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_parse/parse_lsa.c (-35 / +25 lines)
Lines 251-257 Link Here
251
251
252
	if (attr->ptr_sec_qos != 0) {
252
	if (attr->ptr_sec_qos != 0) {
253
		if (UNMARSHALLING(ps))
253
		if (UNMARSHALLING(ps))
254
			if (!(attr->sec_qos = (LSA_SEC_QOS *)prs_alloc_mem(ps,sizeof(LSA_SEC_QOS))))
254
			if (!(attr->sec_qos = PRS_ALLOC_MEM( ps, LSA_SEC_QOS, 1 )))
255
				return False;
255
				return False;
256
256
257
		if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth))
257
		if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth))
Lines 538-550 Link Here
538
                r_e->ptr_enum_domains = 1;
538
                r_e->ptr_enum_domains = 1;
539
                r_e->num_domains2 = 1;
539
                r_e->num_domains2 = 1;
540
		
540
		
541
		if (!(r_e->hdr_domain_name = (UNIHDR2 *)talloc(ctx,sizeof(UNIHDR2))))
541
		if (!(r_e->hdr_domain_name = TALLOC_P(ctx,UNIHDR2)))
542
			return;
542
			return;
543
543
544
		if (!(r_e->uni_domain_name = (UNISTR2 *)talloc(ctx,sizeof(UNISTR2))))
544
		if (!(r_e->uni_domain_name = TALLOC_P(ctx,UNISTR2)))
545
			return;
545
			return;
546
546
547
		if (!(r_e->domain_sid = (DOM_SID2 *)talloc(ctx,sizeof(DOM_SID2))))
547
		if (!(r_e->domain_sid = TALLOC_P(ctx,DOM_SID2)))
548
			return;
548
			return;
549
549
550
		init_uni_hdr2(&r_e->hdr_domain_name[0], len_domain_name);
550
		init_uni_hdr2(&r_e->hdr_domain_name[0], len_domain_name);
Lines 585-597 Link Here
585
		num_domains = r_e->num_domains2;
585
		num_domains = r_e->num_domains2;
586
586
587
		if (UNMARSHALLING(ps)) {
587
		if (UNMARSHALLING(ps)) {
588
			if (!(r_e->hdr_domain_name = (UNIHDR2 *)prs_alloc_mem(ps,sizeof(UNIHDR2) * num_domains)))
588
			if (!(r_e->hdr_domain_name = PRS_ALLOC_MEM( ps, UNIHDR2, num_domains )))
589
				return False;
589
				return False;
590
590
591
			if (!(r_e->uni_domain_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2) * num_domains)))
591
			if (!(r_e->uni_domain_name = PRS_ALLOC_MEM( ps, UNISTR2, num_domains )))
592
				return False;
592
				return False;
593
593
594
			if (!(r_e->domain_sid = (DOM_SID2 *)prs_alloc_mem(ps,sizeof(DOM_SID2) * num_domains)))
594
			if (!(r_e->domain_sid = PRS_ALLOC_MEM( ps, DOM_SID2, num_domains )))
595
				return False;
595
				return False;
596
		}
596
		}
597
597
Lines 686-692 Link Here
686
		return False;
686
		return False;
687
687
688
	if (UNMARSHALLING(ps)) {
688
	if (UNMARSHALLING(ps)) {
689
		d_q->auditsettings = (uint32 *)talloc_zero(ps->mem_ctx, d_q->count2 * sizeof(uint32));
689
		d_q->auditsettings = (uint32 *)TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
690
	}
690
	}
691
691
692
	if (d_q->auditsettings == NULL) {
692
	if (d_q->auditsettings == NULL) {
Lines 807-820 Link Here
807
807
808
	if (num_entries == 0) return;
808
	if (num_entries == 0) return;
809
809
810
	if ((sen->ptr_sid = (uint32 *)talloc_zero(mem_ctx, num_entries * 
810
	if ((sen->ptr_sid = (uint32 *)TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries)) == NULL) {
811
					     sizeof(uint32))) == NULL) {
812
		DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
811
		DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
813
		return;
812
		return;
814
	}
813
	}
815
814
816
	if ((sen->sid = (DOM_SID2 *)talloc_zero(mem_ctx, num_entries * 
815
	if ((sen->sid = (DOM_SID2 *)TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
817
					   sizeof(DOM_SID2))) == NULL) {
818
		DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
816
		DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
819
		return;
817
		return;
820
	}
818
	}
Lines 861-875 Link Here
861
	/* Mallocate memory if we're unpacking from the wire */
859
	/* Mallocate memory if we're unpacking from the wire */
862
860
863
	if (UNMARSHALLING(ps)) {
861
	if (UNMARSHALLING(ps)) {
864
		if ((sen->ptr_sid = (uint32 *)prs_alloc_mem( ps,
862
		if ((sen->ptr_sid = PRS_ALLOC_MEM( ps, uint32, sen->num_entries )) == NULL) {
865
			sen->num_entries * sizeof(uint32))) == NULL) {
866
			DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
863
			DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
867
				  "ptr_sid\n"));
864
				  "ptr_sid\n"));
868
			return False;
865
			return False;
869
		}
866
		}
870
867
871
		if ((sen->sid = (DOM_SID2 *)prs_alloc_mem( ps,
868
		if ((sen->sid = PRS_ALLOC_MEM( ps, DOM_SID2, sen->num_entries )) == NULL) {
872
			sen->num_entries * sizeof(DOM_SID2))) == NULL) {
873
			DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
869
			DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
874
				  "sids\n"));
870
				  "sids\n"));
875
			return False;
871
			return False;
Lines 969-983 Link Here
969
			return False;
965
			return False;
970
966
971
		if (UNMARSHALLING(ps)) {
967
		if (UNMARSHALLING(ps)) {
972
			if ((trn->name = (LSA_TRANS_NAME *)
968
			if ((trn->name = PRS_ALLOC_MEM( ps, LSA_TRANS_NAME, trn->num_entries )) == NULL) {
973
			     prs_alloc_mem(ps, trn->num_entries * 
974
				    sizeof(LSA_TRANS_NAME))) == NULL) {
975
				return False;
969
				return False;
976
			}
970
			}
977
971
978
			if ((trn->uni_name = (UNISTR2 *)
972
			if ((trn->uni_name = PRS_ALLOC_MEM( ps, UNISTR2, trn->num_entries )) == NULL) {
979
			     prs_alloc_mem(ps, trn->num_entries *
980
				    sizeof(UNISTR2))) == NULL) {
981
				return False;
973
				return False;
982
			}
974
			}
983
		}
975
		}
Lines 1057-1070 Link Here
1057
	q_l->num_entries2 = num_names;
1049
	q_l->num_entries2 = num_names;
1058
	q_l->lookup_level = 1;
1050
	q_l->lookup_level = 1;
1059
1051
1060
	if ((q_l->uni_name = (UNISTR2 *)talloc_zero(
1052
	if ((q_l->uni_name = (UNISTR2 *)TALLOC_ZERO_ARRAY(
1061
		mem_ctx, num_names * sizeof(UNISTR2))) == NULL) {
1053
		mem_ctx, UNISTR2, num_names)) == NULL) {
1062
		DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1054
		DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1063
		return;
1055
		return;
1064
	}
1056
	}
1065
1057
1066
	if ((q_l->hdr_name = (UNIHDR *)talloc_zero(
1058
	if ((q_l->hdr_name = (UNIHDR *)TALLOC_ZERO_ARRAY(
1067
		mem_ctx, num_names * sizeof(UNIHDR))) == NULL) {
1059
		mem_ctx, UNIHDR, num_names)) == NULL) {
1068
		DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1060
		DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1069
		return;
1061
		return;
1070
	}
1062
	}
Lines 1105-1115 Link Here
1105
1097
1106
	if (UNMARSHALLING(ps)) {
1098
	if (UNMARSHALLING(ps)) {
1107
		if (q_r->num_entries) {
1099
		if (q_r->num_entries) {
1108
			if ((q_r->hdr_name = (UNIHDR *)prs_alloc_mem(ps,
1100
			if ((q_r->hdr_name = PRS_ALLOC_MEM( ps, UNIHDR, q_r->num_entries )) == NULL)
1109
					q_r->num_entries * sizeof(UNIHDR))) == NULL)
1110
				return False;
1101
				return False;
1111
			if ((q_r->uni_name = (UNISTR2 *)prs_alloc_mem(ps,
1102
			if ((q_r->uni_name = PRS_ALLOC_MEM( ps, UNISTR2, q_r->num_entries )) == NULL)
1112
					q_r->num_entries * sizeof(UNISTR2))) == NULL)
1113
				return False;
1103
				return False;
1114
		}
1104
		}
1115
	}
1105
	}
Lines 1179-1185 Link Here
1179
		}
1169
		}
1180
1170
1181
		if (UNMARSHALLING(ps)) {
1171
		if (UNMARSHALLING(ps)) {
1182
			if ((r_r->dom_rid = (DOM_RID2 *)prs_alloc_mem(ps, r_r->num_entries2 * sizeof(DOM_RID2)))
1172
			if ((r_r->dom_rid = PRS_ALLOC_MEM( ps, DOM_RID2, r_r->num_entries2 ))
1183
			    == NULL) {
1173
			    == NULL) {
1184
				DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
1174
				DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
1185
				return False;
1175
				return False;
Lines 1401-1407 Link Here
1401
			return False;
1391
			return False;
1402
1392
1403
		if (UNMARSHALLING(ps))
1393
		if (UNMARSHALLING(ps))
1404
			if (!(r_q->privs = (LSA_PRIV_ENTRY *)prs_alloc_mem(ps, sizeof(LSA_PRIV_ENTRY) * r_q->count1)))
1394
			if (!(r_q->privs = PRS_ALLOC_MEM(ps, LSA_PRIV_ENTRY, r_q->count1)))
1405
				return False;
1395
				return False;
1406
1396
1407
		if (!lsa_io_priv_entries("", r_q->privs, r_q->count1, ps, depth))
1397
		if (!lsa_io_priv_entries("", r_q->privs, r_q->count1, ps, depth))
Lines 1834-1840 Link Here
1834
		/* malloc memory if unmarshalling here */
1824
		/* malloc memory if unmarshalling here */
1835
1825
1836
		if (UNMARSHALLING(ps) && r_c->count!=0) {
1826
		if (UNMARSHALLING(ps) && r_c->count!=0) {
1837
			if (!(r_c->set.set = (LUID_ATTR *)prs_alloc_mem(ps,sizeof(LUID_ATTR) * r_c->count)))
1827
			if (!(r_c->set.set = PRS_ALLOC_MEM( ps, LUID_ATTR, r_c->count )))
1838
				return False;
1828
				return False;
1839
1829
1840
		}
1830
		}
Lines 2006-2012 Link Here
2006
		return False;
1996
		return False;
2007
1997
2008
	if (UNMARSHALLING(ps) && r_c->count!=0) {
1998
	if (UNMARSHALLING(ps) && r_c->count!=0) {
2009
		if (!(r_c->set.set = (LUID_ATTR *)prs_alloc_mem(ps,sizeof(LUID_ATTR) * r_c->count)))
1999
		if (!(r_c->set.set = PRS_ALLOC_MEM( ps, LUID_ATTR, r_c->count )))
2010
			return False;
2000
			return False;
2011
	}
2001
	}
2012
	
2002
	
Lines 2065-2071 Link Here
2065
			return False;
2055
			return False;
2066
2056
2067
		if (UNMARSHALLING(ps) && r_c->count!=0) {
2057
		if (UNMARSHALLING(ps) && r_c->count!=0) {
2068
			if (!(r_c->set.set = (LUID_ATTR *)prs_alloc_mem(ps,sizeof(LUID_ATTR) * r_c->count)))
2058
			if (!(r_c->set.set = PRS_ALLOC_MEM(ps,LUID_ATTR, r_c->count)))
2069
				return False;
2059
				return False;
2070
		}
2060
		}
2071
2061
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_parse/parse_misc.c (-36 / +22 lines)
Lines 529-544 Link Here
529
529
530
	len = strlen(buf) + 1;
530
	len = strlen(buf) + 1;
531
531
532
	if (len < MAX_UNISTRLEN)
532
	len = MAX(len, MAX_UNISTRLEN);
533
		len = MAX_UNISTRLEN;
534
	len *= sizeof(uint16);
535
533
536
	str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
534
	str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
537
	if (str->buffer == NULL)
535
	if (str->buffer == NULL)
538
		smb_panic("init_unistr: malloc fail\n");
536
		smb_panic("init_unistr: malloc fail\n");
539
537
540
	/* store the string (null-terminated copy) */
538
	/* store the string (null-terminated copy) */
541
	dos_struni2((char *)str->buffer, buf, len);
539
	dos_struni2((char *)str->buffer, buf, sizeof(uint16)*len);
542
}
540
}
543
541
544
/*******************************************************************
542
/*******************************************************************
Lines 566-575 Link Here
566
564
567
static void create_buffer3(BUFFER3 *str, size_t len)
565
static void create_buffer3(BUFFER3 *str, size_t len)
568
{
566
{
569
	if (len < MAX_BUFFERLEN)
567
	len = MAX(len,MAX_BUFFERLEN);
570
		len = MAX_BUFFERLEN;
571
568
572
	str->buffer = talloc_zero(get_talloc_ctx(), len);
569
	str->buffer = TALLOC_ZERO(get_talloc_ctx(), len);
573
	if (str->buffer == NULL)
570
	if (str->buffer == NULL)
574
		smb_panic("create_buffer3: talloc fail\n");
571
		smb_panic("create_buffer3: talloc fail\n");
575
572
Lines 658-664 Link Here
658
		return False;
655
		return False;
659
656
660
	if (UNMARSHALLING(ps)) {
657
	if (UNMARSHALLING(ps)) {
661
		buf3->buffer = (unsigned char *)prs_alloc_mem(ps, buf3->buf_max_len);
658
		buf3->buffer = PRS_ALLOC_MEM( ps, unsigned char, buf3->buf_max_len );
662
		if (buf3->buffer == NULL)
659
		if (buf3->buffer == NULL)
663
			return False;
660
			return False;
664
	}
661
	}
Lines 710-718 Link Here
710
	str->buf_len = buf != NULL ? len : 0;
707
	str->buf_len = buf != NULL ? len : 0;
711
708
712
	if (buf != NULL) {
709
	if (buf != NULL) {
713
		if (len < MAX_BUFFERLEN)
710
		len = MAX(len, MAX_BUFFERLEN);
714
			len = MAX_BUFFERLEN;
711
		str->buffer = TALLOC_ZERO(get_talloc_ctx(), len);
715
		str->buffer = talloc_zero(get_talloc_ctx(), len);
716
		if (str->buffer == NULL)
712
		if (str->buffer == NULL)
717
			smb_panic("init_buffer2: talloc fail\n");
713
			smb_panic("init_buffer2: talloc fail\n");
718
		memcpy(str->buffer, buf, MIN(str->buf_len, len));
714
		memcpy(str->buffer, buf, MIN(str->buf_len, len));
Lines 799-813 Link Here
799
	   (the the length of the source string) to prevent
795
	   (the the length of the source string) to prevent
800
	   reallocation of memory. */
796
	   reallocation of memory. */
801
	if (str->buffer == NULL) {
797
	if (str->buffer == NULL) {
802
		size_t len = from->uni_max_len * sizeof(uint16);
798
	    size_t alloc_len = MAX(from->uni_max_len,MAX_UNISTRLEN);
803
799
	    str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, alloc_len);
804
		if (len < MAX_UNISTRLEN)
800
	    if ((str->buffer == NULL)) {
805
			len = MAX_UNISTRLEN;
806
		len *= sizeof(uint16);
807
808
   		str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
809
		if ((str->buffer == NULL) && (len > 0 ))
810
		{
811
			smb_panic("copy_unistr2: talloc fail\n");
801
			smb_panic("copy_unistr2: talloc fail\n");
812
			return;
802
			return;
813
		}
803
		}
Lines 823-830 Link Here
823
813
824
void init_string2(STRING2 *str, const char *buf, int max_len, int str_len)
814
void init_string2(STRING2 *str, const char *buf, int max_len, int str_len)
825
{
815
{
826
	int alloc_len = 0;
827
828
	/* set up string lengths. */
816
	/* set up string lengths. */
829
	str->str_max_len = max_len;
817
	str->str_max_len = max_len;
830
	str->undoc       = 0;
818
	str->undoc       = 0;
Lines 832-840 Link Here
832
820
833
	/* store the string */
821
	/* store the string */
834
	if(str_len != 0) {
822
	if(str_len != 0) {
835
		if (str_len < MAX_STRINGLEN)
823
		int alloc_len = MAX(str_len,MAX_STRINGLEN);
836
			alloc_len = MAX_STRINGLEN;
824
		str->buffer = TALLOC_ZERO(get_talloc_ctx(), alloc_len);
837
		str->buffer = talloc_zero(get_talloc_ctx(), alloc_len);
838
		if (str->buffer == NULL)
825
		if (str->buffer == NULL)
839
			smb_panic("init_string2: malloc fail\n");
826
			smb_panic("init_string2: malloc fail\n");
840
		memcpy(str->buffer, buf, str_len);
827
		memcpy(str->buffer, buf, str_len);
Lines 897-913 Link Here
897
	str->undoc       = 0;
884
	str->undoc       = 0;
898
	str->uni_str_len = (uint32)len;
885
	str->uni_str_len = (uint32)len;
899
886
900
	if (len < MAX_UNISTRLEN)
887
	len = MAX(len, MAX_UNISTRLEN);
901
		len = MAX_UNISTRLEN;
902
	len *= sizeof(uint16);
903
888
904
	str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
889
	str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
905
	if ((str->buffer == NULL) && (len > 0))
890
	if (str->buffer == NULL)
906
	{
891
	{
907
		smb_panic("init_unistr2: malloc fail\n");
892
		smb_panic("init_unistr2: malloc fail\n");
908
		return;
893
		return;
909
	}
894
	}
910
895
896
	/* Ensure len is the length in *bytes* */
897
	len *= sizeof(uint16);
898
911
	/*
899
	/*
912
	 * don't move this test above ! The UNISTR2 must be initialized !!!
900
	 * don't move this test above ! The UNISTR2 must be initialized !!!
913
	 * jfm, 7/7/2001.
901
	 * jfm, 7/7/2001.
Lines 950-956 Link Here
950
	to->uni_str_len = i;
938
	to->uni_str_len = i;
951
939
952
	/* allocate the space and copy the string buffer */
940
	/* allocate the space and copy the string buffer */
953
	to->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), sizeof(uint16)*(to->uni_str_len));
941
	to->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, to->uni_str_len);
954
	if (to->buffer == NULL)
942
	if (to->buffer == NULL)
955
		smb_panic("init_unistr2_from_unistr: malloc fail\n");
943
		smb_panic("init_unistr2_from_unistr: malloc fail\n");
956
	memcpy(to->buffer, from->buffer, to->uni_max_len*sizeof(uint16));
944
	memcpy(to->buffer, from->buffer, to->uni_max_len*sizeof(uint16));
Lines 1482-1495 Link Here
1482
	if (len < MAX_UNISTRLEN)
1470
	if (len < MAX_UNISTRLEN)
1483
		len = MAX_UNISTRLEN;
1471
		len = MAX_UNISTRLEN;
1484
1472
1485
	len *= sizeof(uint16);
1473
	str->str.buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
1486
1487
	str->str.buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
1488
	if (str->str.buffer == NULL)
1474
	if (str->str.buffer == NULL)
1489
		smb_panic("init_unistr3: malloc fail\n");
1475
		smb_panic("init_unistr3: malloc fail\n");
1490
1476
1491
	/* store the string (null-terminated copy) */
1477
	/* store the string (null-terminated copy) */
1492
	dos_struni2((char *)str->str.buffer, buf, len);
1478
	dos_struni2((char *)str->str.buffer, buf, len*sizeof(uint16));
1493
}
1479
}
1494
1480
1495
/*******************************************************************
1481
/*******************************************************************
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_parse/parse_net.c (-26 / +14 lines)
Lines 824-830 Link Here
824
			;
824
			;
825
825
826
		/* Now allocate space for them. */
826
		/* Now allocate space for them. */
827
		*ppsids = (DOM_SID2 *)talloc_zero(ctx, count * sizeof(DOM_SID2));
827
		*ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
828
		if (*ppsids == NULL)
828
		if (*ppsids == NULL)
829
			return 0;
829
			return 0;
830
830
Lines 1121-1127 Link Here
1121
	depth++;
1121
	depth++;
1122
1122
1123
	if (UNMARSHALLING(ps)) {
1123
	if (UNMARSHALLING(ps)) {
1124
		ctr = *pp_ctr = (NET_ID_INFO_CTR *)prs_alloc_mem(ps, sizeof(NET_ID_INFO_CTR));
1124
		ctr = *pp_ctr = PRS_ALLOC_MEM( ps, NET_ID_INFO_CTR, 1 );
1125
		if (ctr == NULL)
1125
		if (ctr == NULL)
1126
			return False;
1126
			return False;
1127
	}
1127
	}
Lines 1291-1297 Link Here
1291
	/* always have at least one group == the user's primary group */
1291
	/* always have at least one group == the user's primary group */
1292
	usr->num_groups2 = num_groups+1;
1292
	usr->num_groups2 = num_groups+1;
1293
1293
1294
	usr->gids = (DOM_GID *)talloc_zero(ctx,sizeof(DOM_GID) * (num_groups+1));
1294
	usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID, num_groups+1);
1295
	if (usr->gids == NULL)
1295
	if (usr->gids == NULL)
1296
		return;
1296
		return;
1297
1297
Lines 1426-1432 Link Here
1426
		return False;
1426
		return False;
1427
1427
1428
	if (UNMARSHALLING(ps) && usr->num_groups2 > 0) {
1428
	if (UNMARSHALLING(ps) && usr->num_groups2 > 0) {
1429
		usr->gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_groups2);
1429
		usr->gids = PRS_ALLOC_MEM( ps, DOM_GID, usr->num_groups2 );
1430
		if (usr->gids == NULL)
1430
		if (usr->gids == NULL)
1431
			return False;
1431
			return False;
1432
	}
1432
	}
Lines 1447-1453 Link Here
1447
	if (usr->num_other_sids) {
1447
	if (usr->num_other_sids) {
1448
1448
1449
		if (UNMARSHALLING(ps)) {
1449
		if (UNMARSHALLING(ps)) {
1450
			usr->other_sids = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(DOM_SID2)*usr->num_other_sids);
1450
			usr->other_sids = PRS_ALLOC_MEM( ps, DOM_SID2, usr->num_other_sids );
1451
			if (usr->other_sids == NULL)
1451
			if (usr->other_sids == NULL)
1452
				return False;
1452
				return False;
1453
		}
1453
		}
Lines 1456-1462 Link Here
1456
			return False;
1456
			return False;
1457
1457
1458
		if (UNMARSHALLING(ps) && usr->num_other_groups > 0) {
1458
		if (UNMARSHALLING(ps) && usr->num_other_groups > 0) {
1459
			usr->other_gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_other_groups);
1459
			usr->other_gids = PRS_ALLOC_MEM( ps, DOM_GID, usr->num_other_groups );
1460
			if (usr->other_gids == NULL)
1460
			if (usr->other_gids == NULL)
1461
				return False;
1461
				return False;
1462
		}
1462
		}
Lines 2130-2137 Link Here
2130
			return False;
2130
			return False;
2131
		}
2131
		}
2132
2132
2133
                info->rids = talloc(ps->mem_ctx, sizeof(uint32) *
2133
                info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
2134
                                    info->num_members2);
2135
2134
2136
                if (info->rids == NULL) {
2135
                if (info->rids == NULL) {
2137
                        DEBUG(0, ("out of memory allocating %d rids\n",
2136
                        DEBUG(0, ("out of memory allocating %d rids\n",
Lines 2158-2165 Link Here
2158
			return False;
2157
			return False;
2159
		}
2158
		}
2160
2159
2161
                info->attribs = talloc(ps->mem_ctx, sizeof(uint32) *
2160
                info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
2162
                                       info->num_members3);
2163
2161
2164
                if (info->attribs == NULL) {
2162
                if (info->attribs == NULL) {
2165
                        DEBUG(0, ("out of memory allocating %d attribs\n",
2163
                        DEBUG(0, ("out of memory allocating %d attribs\n",
Lines 2245-2252 Link Here
2245
			return False;
2243
			return False;
2246
		}
2244
		}
2247
2245
2248
                info->ptr_sids = talloc(ps->mem_ctx, sizeof(uint32) *
2246
                info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
2249
                                        info->num_sids);
2250
                
2247
                
2251
                if (info->ptr_sids == NULL) {
2248
                if (info->ptr_sids == NULL) {
2252
                        DEBUG(0, ("out of memory allocating %d ptr_sids\n",
2249
                        DEBUG(0, ("out of memory allocating %d ptr_sids\n",
Lines 2261-2268 Link Here
2261
                                return False;
2258
                                return False;
2262
		}
2259
		}
2263
2260
2264
                info->sids = talloc(ps->mem_ctx, sizeof(DOM_SID2) *
2261
                info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
2265
                                    info->num_sids);
2266
2262
2267
                if (info->sids == NULL) {
2263
                if (info->sids == NULL) {
2268
                        DEBUG(0, ("error allocating %d sids\n",
2264
                        DEBUG(0, ("error allocating %d sids\n",
Lines 2402-2410 Link Here
2402
			}
2398
			}
2403
2399
2404
                        if (r_s->num_deltas2 > 0) {
2400
                        if (r_s->num_deltas2 > 0) {
2405
                                r_s->hdr_deltas = (SAM_DELTA_HDR *)
2401
                                r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
2406
                                        talloc(ps->mem_ctx, r_s->num_deltas2 *
2407
                                               sizeof(SAM_DELTA_HDR));
2408
                          
2402
                          
2409
                                if (r_s->hdr_deltas == NULL) {
2403
                                if (r_s->hdr_deltas == NULL) {
2410
                                        DEBUG(0, ("error tallocating memory "
2404
                                        DEBUG(0, ("error tallocating memory "
Lines 2423-2431 Link Here
2423
			}
2417
			}
2424
2418
2425
                        if (r_s->num_deltas2 > 0) {
2419
                        if (r_s->num_deltas2 > 0) {
2426
                                r_s->deltas = (SAM_DELTA_CTR *)
2420
                                r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2 );
2427
                                        talloc(ps->mem_ctx, r_s->num_deltas2 *
2428
                                               sizeof(SAM_DELTA_CTR));
2429
2421
2430
                                if (r_s->deltas == NULL) {
2422
                                if (r_s->deltas == NULL) {
2431
                                        DEBUG(0, ("error tallocating memory "
2423
                                        DEBUG(0, ("error tallocating memory "
Lines 2538-2546 Link Here
2538
		if (r_s->ptr_deltas != 0)
2530
		if (r_s->ptr_deltas != 0)
2539
		{
2531
		{
2540
                        if (r_s->num_deltas > 0) {
2532
                        if (r_s->num_deltas > 0) {
2541
                                r_s->hdr_deltas = (SAM_DELTA_HDR *)
2533
                                r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
2542
                                        talloc(ps->mem_ctx, r_s->num_deltas *
2543
                                               sizeof(SAM_DELTA_HDR));
2544
                                if (r_s->hdr_deltas == NULL) {
2534
                                if (r_s->hdr_deltas == NULL) {
2545
                                        DEBUG(0, ("error tallocating memory "
2535
                                        DEBUG(0, ("error tallocating memory "
2546
                                                  "for %d delta headers\n", 
2536
                                                  "for %d delta headers\n", 
Lines 2556-2564 Link Here
2556
			}
2546
			}
2557
                        
2547
                        
2558
                        if (r_s->num_deltas > 0) {
2548
                        if (r_s->num_deltas > 0) {
2559
                                r_s->deltas = (SAM_DELTA_CTR *)
2549
                                r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas );
2560
                                        talloc(ps->mem_ctx, r_s->num_deltas *
2561
                                               sizeof(SAM_DELTA_CTR));
2562
2550
2563
                                if (r_s->deltas == NULL) {
2551
                                if (r_s->deltas == NULL) {
2564
                                        DEBUG(0, ("error tallocating memory "
2552
                                        DEBUG(0, ("error tallocating memory "
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_parse/parse_prs.c (-25 / +11 lines)
Lines 83-89 Link Here
83
83
84
	if (size != 0) {
84
	if (size != 0) {
85
		ps->buffer_size = size;
85
		ps->buffer_size = size;
86
		if((ps->data_p = (char *)malloc((size_t)size)) == NULL) {
86
		if((ps->data_p = (char *)SMB_MALLOC((size_t)size)) == NULL) {
87
			DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size));
87
			DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size));
88
			return False;
88
			return False;
89
		}
89
		}
Lines 136-155 Link Here
136
}
136
}
137
137
138
/*******************************************************************
138
/*******************************************************************
139
 Allocate memory when unmarshalling... Always zero clears.
140
 ********************************************************************/
141
142
char *prs_alloc_mem(prs_struct *ps, size_t size)
143
{
144
	char *ret = talloc(ps->mem_ctx, size);
145
146
	if (ret)
147
		memset(ret, '\0', size);
148
149
	return ret;
150
}
151
152
/*******************************************************************
153
 Return the current talloc context we're using.
139
 Return the current talloc context we're using.
154
 ********************************************************************/
140
 ********************************************************************/
155
141
Lines 193-199 Link Here
193
		return prs_force_grow(ps, newsize - ps->buffer_size);
179
		return prs_force_grow(ps, newsize - ps->buffer_size);
194
180
195
	if (newsize < ps->buffer_size) {
181
	if (newsize < ps->buffer_size) {
196
		char *new_data_p = Realloc(ps->data_p, newsize);
182
		char *new_data_p = SMB_REALLOC(ps->data_p, newsize);
197
		/* if newsize is zero, Realloc acts like free() & returns NULL*/
183
		/* if newsize is zero, Realloc acts like free() & returns NULL*/
198
		if (new_data_p == NULL && newsize != 0) {
184
		if (new_data_p == NULL && newsize != 0) {
199
			DEBUG(0,("prs_set_buffer_size: Realloc failure for size %u.\n",
185
			DEBUG(0,("prs_set_buffer_size: Realloc failure for size %u.\n",
Lines 247-253 Link Here
247
233
248
		new_size = MAX(MAX_PDU_FRAG_LEN,extra_space);
234
		new_size = MAX(MAX_PDU_FRAG_LEN,extra_space);
249
235
250
		if((new_data = malloc(new_size)) == NULL) {
236
		if((new_data = SMB_MALLOC(new_size)) == NULL) {
251
			DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
237
			DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
252
			return False;
238
			return False;
253
		}
239
		}
Lines 259-265 Link Here
259
		 */
245
		 */
260
		new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);		
246
		new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);		
261
247
262
		if ((new_data = Realloc(ps->data_p, new_size)) == NULL) {
248
		if ((new_data = SMB_REALLOC(ps->data_p, new_size)) == NULL) {
263
			DEBUG(0,("prs_grow: Realloc failure for size %u.\n",
249
			DEBUG(0,("prs_grow: Realloc failure for size %u.\n",
264
				(unsigned int)new_size));
250
				(unsigned int)new_size));
265
			return False;
251
			return False;
Lines 290-296 Link Here
290
		return False;
276
		return False;
291
	}
277
	}
292
278
293
	if((new_data = Realloc(ps->data_p, new_size)) == NULL) {
279
	if((new_data = SMB_REALLOC(ps->data_p, new_size)) == NULL) {
294
		DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n",
280
		DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n",
295
			(unsigned int)new_size));
281
			(unsigned int)new_size));
296
		return False;
282
		return False;
Lines 839-845 Link Here
839
		return False;
825
		return False;
840
826
841
	if (UNMARSHALLING(ps)) {
827
	if (UNMARSHALLING(ps)) {
842
		str->buffer = (uint16 *)prs_alloc_mem(ps,str->buf_len * sizeof(uint16));
828
		str->buffer = PRS_ALLOC_MEM( ps, uint16, str->buf_len );
843
		if (str->buffer == NULL)
829
		if (str->buffer == NULL)
844
			return False;
830
			return False;
845
	}
831
	}
Lines 870-876 Link Here
870
		return False;
856
		return False;
871
857
872
	if (UNMARSHALLING(ps)) {
858
	if (UNMARSHALLING(ps)) {
873
		str->buffer = (uint16 *)prs_alloc_mem(ps,str->buf_len);
859
		str->buffer = PRS_ALLOC_MEM( ps, uint16, str->buf_len );
874
		if (str->buffer == NULL)
860
		if (str->buffer == NULL)
875
			return False;
861
			return False;
876
	}
862
	}
Lines 896-902 Link Here
896
		return False;
882
		return False;
897
883
898
	if (UNMARSHALLING(ps)) {
884
	if (UNMARSHALLING(ps)) {
899
		str->buffer = (unsigned char *)prs_alloc_mem(ps,str->str_max_len);
885
		str->buffer = PRS_ALLOC_MEM( ps, unsigned char, str->str_max_len );
900
		if (str->buffer == NULL)
886
		if (str->buffer == NULL)
901
			return False;
887
			return False;
902
	}
888
	}
Lines 940-946 Link Here
940
		return True;
926
		return True;
941
927
942
	if (UNMARSHALLING(ps)) {
928
	if (UNMARSHALLING(ps)) {
943
		str->buffer = (uint16 *)prs_alloc_mem(ps,str->uni_max_len * sizeof(uint16));
929
		str->buffer = PRS_ALLOC_MEM( ps, uint16, str->uni_max_len );
944
		if (str->buffer == NULL)
930
		if (str->buffer == NULL)
945
			return False;
931
			return False;
946
	}
932
	}
Lines 967-973 Link Here
967
		return False;
953
		return False;
968
954
969
	if (UNMARSHALLING(ps)) {
955
	if (UNMARSHALLING(ps)) {
970
		str->str.buffer = (uint16 *)prs_alloc_mem(ps,str->uni_str_len * sizeof(uint16));
956
		str->str.buffer = PRS_ALLOC_MEM(ps, uint16, str->uni_str_len );
971
		if (str->str.buffer == NULL)
957
		if (str->str.buffer == NULL)
972
			return False;
958
			return False;
973
	}
959
	}
Lines 1055-1061 Link Here
1055
			;
1041
			;
1056
1042
1057
		/* should we allocate anything at all? */
1043
		/* should we allocate anything at all? */
1058
		str->buffer = (uint16 *)prs_alloc_mem(ps,alloc_len * sizeof(uint16));
1044
		str->buffer = PRS_ALLOC_MEM( ps, uint16, alloc_len );
1059
		if ((str->buffer == NULL) && (alloc_len > 0))
1045
		if ((str->buffer == NULL) && (alloc_len > 0))
1060
			return False;
1046
			return False;
1061
1047
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_parse/parse_samr.c (-84 / +62 lines)
Lines 1346-1353 Link Here
1346
			return False;
1346
			return False;
1347
1347
1348
		if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
1348
		if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
1349
			r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
1349
			r_u->sam = PRS_ALLOC_MEM( ps, SAM_ENTRY, r_u->num_entries2 );
1350
			r_u->uni_acct_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
1350
			r_u->uni_acct_name = PRS_ALLOC_MEM( ps, UNISTR2, r_u->num_entries2 );
1351
		}
1351
		}
1352
1352
1353
		if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
1353
		if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
Lines 1451-1461 Link Here
1451
	if (num_entries==0)
1451
	if (num_entries==0)
1452
		return NT_STATUS_OK;
1452
		return NT_STATUS_OK;
1453
1453
1454
	sam->sam=(SAM_ENTRY1 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY1));
1454
	sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY1, num_entries);
1455
	if (!sam->sam)
1455
	if (!sam->sam)
1456
		return NT_STATUS_NO_MEMORY;
1456
		return NT_STATUS_NO_MEMORY;
1457
1457
1458
	sam->str=(SAM_STR1 *)talloc(ctx, num_entries*sizeof(SAM_STR1));
1458
	sam->str=TALLOC_ARRAY(ctx, SAM_STR1, num_entries);
1459
	if (!sam->str)
1459
	if (!sam->str)
1460
		return NT_STATUS_NO_MEMORY;
1460
		return NT_STATUS_NO_MEMORY;
1461
1461
Lines 1505-1520 Link Here
1505
1505
1506
	if (UNMARSHALLING(ps) && num_entries > 0) {
1506
	if (UNMARSHALLING(ps) && num_entries > 0) {
1507
1507
1508
		if ((sam->sam = (SAM_ENTRY1 *)
1508
		if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY1, num_entries)) == NULL) {
1509
		     prs_alloc_mem(ps, sizeof(SAM_ENTRY1) *
1510
				   num_entries)) == NULL) {
1511
			DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
1509
			DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
1512
			return False;
1510
			return False;
1513
		}
1511
		}
1514
1512
1515
		if ((sam->str = (SAM_STR1 *)
1513
		if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR1, num_entries)) == NULL) {
1516
		     prs_alloc_mem(ps, sizeof(SAM_STR1) * 
1517
				   num_entries)) == NULL) {
1518
			DEBUG(0, ("out of memory allocating SAM_STR1\n"));
1514
			DEBUG(0, ("out of memory allocating SAM_STR1\n"));
1519
			return False;
1515
			return False;
1520
		}
1516
		}
Lines 1554-1563 Link Here
1554
	if (num_entries==0)
1550
	if (num_entries==0)
1555
		return NT_STATUS_OK;
1551
		return NT_STATUS_OK;
1556
1552
1557
	if (!(sam->sam=(SAM_ENTRY2 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY2))))
1553
	if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY2, num_entries)))
1558
		return NT_STATUS_NO_MEMORY;
1554
		return NT_STATUS_NO_MEMORY;
1559
1555
1560
	if (!(sam->str=(SAM_STR2 *)talloc(ctx, num_entries*sizeof(SAM_STR2))))
1556
	if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR2, num_entries)))
1561
		return NT_STATUS_NO_MEMORY;
1557
		return NT_STATUS_NO_MEMORY;
1562
1558
1563
	ZERO_STRUCTP(sam->sam);
1559
	ZERO_STRUCTP(sam->sam);
Lines 1605-1620 Link Here
1605
1601
1606
	if (UNMARSHALLING(ps) && num_entries > 0) {
1602
	if (UNMARSHALLING(ps) && num_entries > 0) {
1607
1603
1608
		if ((sam->sam = (SAM_ENTRY2 *)
1604
		if ((sam->sam = PRS_ALLOC_MEM( ps, SAM_ENTRY2, num_entries )) == NULL) {
1609
		     prs_alloc_mem(ps, sizeof(SAM_ENTRY2) *
1610
				   num_entries)) == NULL) {
1611
			DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
1605
			DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
1612
			return False;
1606
			return False;
1613
		}
1607
		}
1614
1608
1615
		if ((sam->str = (SAM_STR2 *)
1609
		if ((sam->str = PRS_ALLOC_MEM( ps, SAM_STR2, num_entries )) == NULL) {
1616
		     prs_alloc_mem(ps, sizeof(SAM_STR2) * 
1617
				   num_entries)) == NULL) {
1618
			DEBUG(0, ("out of memory allocating SAM_STR2\n"));
1610
			DEBUG(0, ("out of memory allocating SAM_STR2\n"));
1619
			return False;
1611
			return False;
1620
		}
1612
		}
Lines 1652-1661 Link Here
1652
	if (num_entries==0)
1644
	if (num_entries==0)
1653
		return NT_STATUS_OK;
1645
		return NT_STATUS_OK;
1654
1646
1655
	if (!(sam->sam=(SAM_ENTRY3 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY3))))
1647
	if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY3, num_entries)))
1656
		return NT_STATUS_NO_MEMORY;
1648
		return NT_STATUS_NO_MEMORY;
1657
1649
1658
	if (!(sam->str=(SAM_STR3 *)talloc(ctx, num_entries*sizeof(SAM_STR3))))
1650
	if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR3, num_entries)))
1659
		return NT_STATUS_NO_MEMORY;
1651
		return NT_STATUS_NO_MEMORY;
1660
1652
1661
	ZERO_STRUCTP(sam->sam);
1653
	ZERO_STRUCTP(sam->sam);
Lines 1699-1714 Link Here
1699
1691
1700
	if (UNMARSHALLING(ps) && num_entries > 0) {
1692
	if (UNMARSHALLING(ps) && num_entries > 0) {
1701
1693
1702
		if ((sam->sam = (SAM_ENTRY3 *)
1694
		if ((sam->sam = PRS_ALLOC_MEM( ps, SAM_ENTRY3, num_entries )) == NULL) {
1703
		     prs_alloc_mem(ps, sizeof(SAM_ENTRY3) *
1704
				   num_entries)) == NULL) {
1705
			DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
1695
			DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
1706
			return False;
1696
			return False;
1707
		}
1697
		}
1708
1698
1709
		if ((sam->str = (SAM_STR3 *)
1699
		if ((sam->str = PRS_ALLOC_MEM( ps, SAM_STR3, num_entries )) == NULL) {
1710
		     prs_alloc_mem(ps, sizeof(SAM_STR3) * 
1711
				   num_entries)) == NULL) {
1712
			DEBUG(0, ("out of memory allocating SAM_STR3\n"));
1700
			DEBUG(0, ("out of memory allocating SAM_STR3\n"));
1713
			return False;
1701
			return False;
1714
		}
1702
		}
Lines 1747-1756 Link Here
1747
	if (num_entries==0)
1735
	if (num_entries==0)
1748
		return NT_STATUS_OK;
1736
		return NT_STATUS_OK;
1749
1737
1750
	if (!(sam->sam=(SAM_ENTRY4 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY4))))
1738
	if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY4, num_entries)))
1751
		return NT_STATUS_NO_MEMORY;
1739
		return NT_STATUS_NO_MEMORY;
1752
1740
1753
	if (!(sam->str=(SAM_STR4 *)talloc(ctx, num_entries*sizeof(SAM_STR4))))
1741
	if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR4, num_entries)))
1754
		return NT_STATUS_NO_MEMORY;
1742
		return NT_STATUS_NO_MEMORY;
1755
1743
1756
	ZERO_STRUCTP(sam->sam);
1744
	ZERO_STRUCTP(sam->sam);
Lines 1792-1807 Link Here
1792
1780
1793
	if (UNMARSHALLING(ps) && num_entries > 0) {
1781
	if (UNMARSHALLING(ps) && num_entries > 0) {
1794
1782
1795
		if ((sam->sam = (SAM_ENTRY4 *)
1783
		if ((sam->sam = PRS_ALLOC_MEM( ps, SAM_ENTRY4, num_entries )) == NULL) {
1796
		     prs_alloc_mem(ps, sizeof(SAM_ENTRY4) *
1797
				   num_entries)) == NULL) {
1798
			DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
1784
			DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
1799
			return False;
1785
			return False;
1800
		}
1786
		}
1801
1787
1802
		if ((sam->str = (SAM_STR4 *)
1788
		if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR4, num_entries )) == NULL) {
1803
		     prs_alloc_mem(ps, sizeof(SAM_STR4) * 
1804
				   num_entries)) == NULL) {
1805
			DEBUG(0, ("out of memory allocating SAM_STR4\n"));
1789
			DEBUG(0, ("out of memory allocating SAM_STR4\n"));
1806
			return False;
1790
			return False;
1807
		}
1791
		}
Lines 1838-1847 Link Here
1838
	if (num_entries==0)
1822
	if (num_entries==0)
1839
		return NT_STATUS_OK;
1823
		return NT_STATUS_OK;
1840
1824
1841
	if (!(sam->sam=(SAM_ENTRY5 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY5))))
1825
	if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY5, num_entries)))
1842
		return NT_STATUS_NO_MEMORY;
1826
		return NT_STATUS_NO_MEMORY;
1843
1827
1844
	if (!(sam->str=(SAM_STR5 *)talloc(ctx, num_entries*sizeof(SAM_STR5))))
1828
	if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR5, num_entries)))
1845
		return NT_STATUS_NO_MEMORY;
1829
		return NT_STATUS_NO_MEMORY;
1846
1830
1847
	ZERO_STRUCTP(sam->sam);
1831
	ZERO_STRUCTP(sam->sam);
Lines 1882-1897 Link Here
1882
1866
1883
	if (UNMARSHALLING(ps) && num_entries > 0) {
1867
	if (UNMARSHALLING(ps) && num_entries > 0) {
1884
1868
1885
		if ((sam->sam = (SAM_ENTRY5 *)
1869
		if ((sam->sam = PRS_ALLOC_MEM( ps, SAM_ENTRY5, num_entries )) == NULL) {
1886
		     prs_alloc_mem(ps, sizeof(SAM_ENTRY5) *
1887
				   num_entries)) == NULL) {
1888
			DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
1870
			DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
1889
			return False;
1871
			return False;
1890
		}
1872
		}
1891
1873
1892
		if ((sam->str = (SAM_STR5 *)
1874
		if ((sam->str = PRS_ALLOC_MEM( ps, SAM_STR5, num_entries )) == NULL) {
1893
		     prs_alloc_mem(ps, sizeof(SAM_STR5) * 
1894
				   num_entries)) == NULL) {
1895
			DEBUG(0, ("out of memory allocating SAM_STR5\n"));
1875
			DEBUG(0, ("out of memory allocating SAM_STR5\n"));
1896
			return False;
1876
			return False;
1897
		}
1877
		}
Lines 2231-2237 Link Here
2231
				prs_struct *ps, int depth)
2211
				prs_struct *ps, int depth)
2232
{
2212
{
2233
	if (UNMARSHALLING(ps))
2213
	if (UNMARSHALLING(ps))
2234
		*ctr = (GROUP_INFO_CTR *)prs_alloc_mem(ps,sizeof(GROUP_INFO_CTR));
2214
		*ctr = PRS_ALLOC_MEM( ps, GROUP_INFO_CTR, 1 );
2235
2215
2236
	if (*ctr == NULL)
2216
	if (*ctr == NULL)
2237
		return False;
2217
		return False;
Lines 2804-2810 Link Here
2804
			if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
2784
			if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
2805
				return False;
2785
				return False;
2806
			if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
2786
			if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
2807
				r_u->rid = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->rid[0])*r_u->num_rids);
2787
				r_u->rid = PRS_ALLOC_MEM( ps, uint32, r_u->num_rids );
2808
				if (r_u->rid == NULL)
2788
				if (r_u->rid == NULL)
2809
					return False;
2789
					return False;
2810
			}
2790
			}
Lines 2820-2826 Link Here
2820
				return False;
2800
				return False;
2821
2801
2822
			if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
2802
			if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
2823
				r_u->attr = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->attr[0])*r_u->num_attrs);
2803
				r_u->attr = PRS_ALLOC_MEM( ps, uint32, r_u->num_attrs );
2824
				if (r_u->attr == NULL)
2804
				if (r_u->attr == NULL)
2825
					return False;
2805
					return False;
2826
			}
2806
			}
Lines 2921-2927 Link Here
2921
2901
2922
	if ((*num_gids) != 0) {
2902
	if ((*num_gids) != 0) {
2923
		if (UNMARSHALLING(ps)) {
2903
		if (UNMARSHALLING(ps)) {
2924
			(*gid) = (DOM_GID *)prs_alloc_mem(ps,sizeof(DOM_GID)*(*num_gids));
2904
			(*gid) = PRS_ALLOC_MEM( ps, DOM_GID, (*num_gids) );
2925
		}
2905
		}
2926
2906
2927
		if ((*gid) == NULL) {
2907
		if ((*gid) == NULL) {
Lines 3076-3083 Link Here
3076
			return False;
3056
			return False;
3077
3057
3078
		if (UNMARSHALLING(ps)) {
3058
		if (UNMARSHALLING(ps)) {
3079
			r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
3059
			r_u->sam = PRS_ALLOC_MEM( ps, SAM_ENTRY, r_u->num_entries2 );
3080
			r_u->uni_dom_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
3060
			r_u->uni_dom_name = PRS_ALLOC_MEM( ps, UNISTR2, r_u->num_entries2 );
3081
		}
3061
		}
3082
3062
3083
		if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
3063
		if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
Lines 3215-3222 Link Here
3215
			return False;
3195
			return False;
3216
3196
3217
		if (UNMARSHALLING(ps)) {
3197
		if (UNMARSHALLING(ps)) {
3218
			r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
3198
			r_u->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY, r_u->num_entries2 );
3219
			r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
3199
			r_u->uni_grp_name = PRS_ALLOC_MEM( ps, UNISTR2, r_u->num_entries2 );
3220
		}
3200
		}
3221
3201
3222
		if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
3202
		if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
Lines 3349-3356 Link Here
3349
			return False;
3329
			return False;
3350
3330
3351
		if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
3331
		if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
3352
			r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
3332
			r_u->sam = PRS_ALLOC_MEM( ps, SAM_ENTRY, r_u->num_entries2 );
3353
			r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
3333
			r_u->uni_grp_name = PRS_ALLOC_MEM( ps, UNISTR2, r_u->num_entries2 );
3354
		}
3334
		}
3355
3335
3356
		if (r_u->num_entries2 != 0 && 
3336
		if (r_u->num_entries2 != 0 && 
Lines 3712-3722 Link Here
3712
		return False;
3692
		return False;
3713
3693
3714
	if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
3694
	if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
3715
		q_u->ptr_sid = (uint32 *)prs_alloc_mem(ps,sizeof(q_u->ptr_sid[0])*q_u->num_sids2);
3695
		q_u->ptr_sid = PRS_ALLOC_MEM( ps, uint32, q_u->num_sids2 );
3716
		if (q_u->ptr_sid == NULL)
3696
		if (q_u->ptr_sid == NULL)
3717
			return False;
3697
			return False;
3718
3698
3719
		q_u->sid = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(q_u->sid[0]) * q_u->num_sids2);
3699
		q_u->sid = PRS_ALLOC_MEM( ps, DOM_SID2, q_u->num_sids2 );
3720
		if (q_u->sid == NULL)
3700
		if (q_u->sid == NULL)
3721
			return False;
3701
			return False;
3722
	}
3702
	}
Lines 3787-3793 Link Here
3787
	if ((*num_rids) != 0) {
3767
	if ((*num_rids) != 0) {
3788
		if (UNMARSHALLING(ps)) {
3768
		if (UNMARSHALLING(ps)) {
3789
			/* reading */
3769
			/* reading */
3790
			(*rid) = (uint32 *)prs_alloc_mem(ps,sizeof(uint32)*(*num_rids));
3770
			(*rid) = PRS_ALLOC_MEM( ps, uint32, (*num_rids) );
3791
		}
3771
		}
3792
		if ((*rid) == NULL)
3772
		if ((*rid) == NULL)
3793
			return False;
3773
			return False;
Lines 3918-3924 Link Here
3918
	q_u->flags = flags;
3898
	q_u->flags = flags;
3919
	q_u->ptr = 0;
3899
	q_u->ptr = 0;
3920
	q_u->num_rids2 = num_rids;
3900
	q_u->num_rids2 = num_rids;
3921
	q_u->rid = (uint32 *)talloc_zero(ctx, num_rids * sizeof(q_u->rid[0]));
3901
	q_u->rid = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids);
3922
	if (q_u->rid == NULL) {
3902
	if (q_u->rid == NULL) {
3923
		q_u->num_rids1 = 0;
3903
		q_u->num_rids1 = 0;
3924
		q_u->num_rids2 = 0;
3904
		q_u->num_rids2 = 0;
Lines 3962-3968 Link Here
3962
		return False;
3942
		return False;
3963
3943
3964
	if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
3944
	if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
3965
		q_u->rid = (uint32 *)prs_alloc_mem(ps, sizeof(q_u->rid[0])*q_u->num_rids2);
3945
		q_u->rid = PRS_ALLOC_MEM( ps, uint32, q_u->num_rids2 );
3966
		if (q_u->rid == NULL)
3946
		if (q_u->rid == NULL)
3967
			return False;
3947
			return False;
3968
	}
3948
	}
Lines 4043-4053 Link Here
4043
4023
4044
4024
4045
		if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
4025
		if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
4046
			r_u->hdr_name = (UNIHDR *) prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->hdr_name[0]));
4026
			r_u->hdr_name = PRS_ALLOC_MEM( ps, UNIHDR, r_u->num_names2 );
4047
			if (r_u->hdr_name == NULL)
4027
			if (r_u->hdr_name == NULL)
4048
				return False;
4028
				return False;
4049
4029
4050
			r_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->uni_name[0]));
4030
			r_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, r_u->num_names2 );
4051
			if (r_u->uni_name == NULL)
4031
			if (r_u->uni_name == NULL)
4052
				return False;
4032
				return False;
4053
		}
4033
		}
Lines 4078-4084 Link Here
4078
			return False;
4058
			return False;
4079
4059
4080
		if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
4060
		if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
4081
			r_u->type = (uint32 *)prs_alloc_mem(ps, r_u->num_types2 * sizeof(r_u->type[0]));
4061
			r_u->type = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2 );
4082
			if (r_u->type == NULL)
4062
			if (r_u->type == NULL)
4083
				return False;
4063
				return False;
4084
		}
4064
		}
Lines 4550-4559 Link Here
4550
	q_u->ptr = 0;
4530
	q_u->ptr = 0;
4551
	q_u->num_names2 = num_names;
4531
	q_u->num_names2 = num_names;
4552
4532
4553
	if (!(q_u->hdr_name = (UNIHDR *)talloc_zero(ctx, num_names * sizeof(UNIHDR))))
4533
	if (!(q_u->hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names)))
4554
		return NT_STATUS_NO_MEMORY;
4534
		return NT_STATUS_NO_MEMORY;
4555
4535
4556
	if (!(q_u->uni_name = (UNISTR2 *)talloc_zero(ctx, num_names * sizeof(UNISTR2))))
4536
	if (!(q_u->uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_names)))
4557
		return NT_STATUS_NO_MEMORY;
4537
		return NT_STATUS_NO_MEMORY;
4558
4538
4559
	for (i = 0; i < num_names; i++) {
4539
	for (i = 0; i < num_names; i++) {
Lines 4599-4608 Link Here
4599
		return False;
4579
		return False;
4600
4580
4601
	if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
4581
	if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
4602
		q_u->hdr_name = (UNIHDR *)prs_alloc_mem(ps, sizeof(UNIHDR) *
4582
		q_u->hdr_name = PRS_ALLOC_MEM( ps, UNIHDR, q_u->num_names2 );
4603
							q_u->num_names2);
4583
		q_u->uni_name = PRS_ALLOC_MEM( ps, UNISTR2, q_u->num_names2 );
4604
		q_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, sizeof(UNISTR2) *
4605
							 q_u->num_names2);
4606
		if (!q_u->hdr_name || !q_u->uni_name)
4584
		if (!q_u->hdr_name || !q_u->uni_name)
4607
			return False;
4585
			return False;
4608
	}
4586
	}
Lines 4642-4650 Link Here
4642
		r_u->ptr_rids = 1;
4620
		r_u->ptr_rids = 1;
4643
		r_u->num_rids2 = num_rids;
4621
		r_u->num_rids2 = num_rids;
4644
4622
4645
		if (!(r_u->rids = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
4623
		if (!(r_u->rids = TALLOC_ZERO_ARRAY(ctx, uint32,num_rids)))
4646
			return NT_STATUS_NO_MEMORY;
4624
			return NT_STATUS_NO_MEMORY;
4647
		if (!(r_u->types = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
4625
		if (!(r_u->types = TALLOC_ZERO_ARRAY(ctx, uint32,num_rids)))
4648
			return NT_STATUS_NO_MEMORY;
4626
			return NT_STATUS_NO_MEMORY;
4649
4627
4650
		if (!r_u->rids || !r_u->types)
4628
		if (!r_u->rids || !r_u->types)
Lines 4711-4717 Link Here
4711
		}
4689
		}
4712
4690
4713
		if (UNMARSHALLING(ps))
4691
		if (UNMARSHALLING(ps))
4714
			r_u->rids = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_rids2);
4692
			r_u->rids = PRS_ALLOC_MEM( ps, uint32, r_u->num_rids2 );
4715
4693
4716
		if (!r_u->rids) {
4694
		if (!r_u->rids) {
4717
			DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
4695
			DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
Lines 4740-4746 Link Here
4740
		}
4718
		}
4741
4719
4742
		if (UNMARSHALLING(ps))
4720
		if (UNMARSHALLING(ps))
4743
			r_u->types = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_types2);
4721
			r_u->types = PRS_ALLOC_MEM( ps, uint32, r_u->num_types2 );
4744
4722
4745
		if (!r_u->types) {
4723
		if (!r_u->types) {
4746
			DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
4724
			DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
Lines 6089-6095 Link Here
6089
6067
6090
	switch (switch_value) {
6068
	switch (switch_value) {
6091
	case 0x10:
6069
	case 0x10:
6092
		ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_10));
6070
		ctr->info.id10 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_10);
6093
		if (ctr->info.id10 == NULL)
6071
		if (ctr->info.id10 == NULL)
6094
			return NT_STATUS_NO_MEMORY;
6072
			return NT_STATUS_NO_MEMORY;
6095
6073
Lines 6105-6111 Link Here
6105
			expire.low = 0xffffffff;
6083
			expire.low = 0xffffffff;
6106
			expire.high = 0x7fffffff;
6084
			expire.high = 0x7fffffff;
6107
6085
6108
			ctr->info.id = (SAM_USER_INFO_11 *) talloc_zero(ctx,sizeof(*ctr->info.id11));
6086
			ctr->info.id = TALLOC_ZERO_P(ctx,SAM_USER_INFO_11);
6109
			init_sam_user_info11(ctr->info.id11, &expire,
6087
			init_sam_user_info11(ctr->info.id11, &expire,
6110
					     "BROOKFIELDS$",	/* name */
6088
					     "BROOKFIELDS$",	/* name */
6111
					     0x03ef,	/* user rid */
6089
					     0x03ef,	/* user rid */
Lines 6116-6122 Link Here
6116
		}
6094
		}
6117
#endif
6095
#endif
6118
	case 0x12:
6096
	case 0x12:
6119
		ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_12));
6097
		ctr->info.id12 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_12);
6120
		if (ctr->info.id12 == NULL)
6098
		if (ctr->info.id12 == NULL)
6121
			return NT_STATUS_NO_MEMORY;
6099
			return NT_STATUS_NO_MEMORY;
6122
6100
Lines 6125-6131 Link Here
6125
	case 21:
6103
	case 21:
6126
		{
6104
		{
6127
			SAM_USER_INFO_21 *cusr;
6105
			SAM_USER_INFO_21 *cusr;
6128
			cusr = (SAM_USER_INFO_21 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_21));
6106
			cusr = TALLOC_ZERO_P(ctx,SAM_USER_INFO_21);
6129
			ctr->info.id21 = cusr;
6107
			ctr->info.id21 = cusr;
6130
			if (ctr->info.id21 == NULL)
6108
			if (ctr->info.id21 == NULL)
6131
				return NT_STATUS_NO_MEMORY;
6109
				return NT_STATUS_NO_MEMORY;
Lines 6184-6190 Link Here
6184
	depth++;
6162
	depth++;
6185
6163
6186
	if (UNMARSHALLING(ps)) {
6164
	if (UNMARSHALLING(ps)) {
6187
		ctr = (SAM_USERINFO_CTR *)prs_alloc_mem(ps,sizeof(SAM_USERINFO_CTR));
6165
		ctr = PRS_ALLOC_MEM( ps, SAM_USERINFO_CTR, 1 );
6188
		if (ctr == NULL)
6166
		if (ctr == NULL)
6189
			return False;
6167
			return False;
6190
		*ppctr = ctr;
6168
		*ppctr = ctr;
Lines 6204-6210 Link Here
6204
	switch (ctr->switch_value) {
6182
	switch (ctr->switch_value) {
6205
	case 0x10:
6183
	case 0x10:
6206
		if (UNMARSHALLING(ps))
6184
		if (UNMARSHALLING(ps))
6207
			ctr->info.id10 = (SAM_USER_INFO_10 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_10));
6185
			ctr->info.id10 = PRS_ALLOC_MEM( ps, SAM_USER_INFO_10, 1);
6208
		if (ctr->info.id10 == NULL) {
6186
		if (ctr->info.id10 == NULL) {
6209
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6187
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6210
			return False;
6188
			return False;
Lines 6213-6219 Link Here
6213
		break;
6191
		break;
6214
	case 0x11:
6192
	case 0x11:
6215
		if (UNMARSHALLING(ps))
6193
		if (UNMARSHALLING(ps))
6216
			ctr->info.id11 = (SAM_USER_INFO_11 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_11));
6194
			ctr->info.id11 = PRS_ALLOC_MEM( ps, SAM_USER_INFO_11, 1 );
6217
6195
6218
		if (ctr->info.id11 == NULL) {
6196
		if (ctr->info.id11 == NULL) {
6219
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6197
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
Lines 6223-6229 Link Here
6223
		break;
6201
		break;
6224
	case 0x12:
6202
	case 0x12:
6225
		if (UNMARSHALLING(ps))
6203
		if (UNMARSHALLING(ps))
6226
			ctr->info.id12 = (SAM_USER_INFO_12 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_12));
6204
			ctr->info.id12 = PRS_ALLOC_MEM( ps, SAM_USER_INFO_12, 1 );
6227
6205
6228
		if (ctr->info.id12 == NULL) {
6206
		if (ctr->info.id12 == NULL) {
6229
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6207
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
Lines 6233-6239 Link Here
6233
		break;
6211
		break;
6234
	case 20:
6212
	case 20:
6235
		if (UNMARSHALLING(ps))
6213
		if (UNMARSHALLING(ps))
6236
			ctr->info.id20 = (SAM_USER_INFO_20 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_20));
6214
			ctr->info.id20 = PRS_ALLOC_MEM( ps, SAM_USER_INFO_20, 1 );
6237
6215
6238
		if (ctr->info.id20 == NULL) {
6216
		if (ctr->info.id20 == NULL) {
6239
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6217
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
Lines 6243-6249 Link Here
6243
		break;
6221
		break;
6244
	case 21:
6222
	case 21:
6245
		if (UNMARSHALLING(ps))
6223
		if (UNMARSHALLING(ps))
6246
			ctr->info.id21 = (SAM_USER_INFO_21 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_21));
6224
			ctr->info.id21 = PRS_ALLOC_MEM( ps, SAM_USER_INFO_21, 1 );
6247
6225
6248
		if (ctr->info.id21 == NULL) {
6226
		if (ctr->info.id21 == NULL) {
6249
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6227
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
Lines 6253-6259 Link Here
6253
		break;
6231
		break;
6254
	case 23:
6232
	case 23:
6255
		if (UNMARSHALLING(ps))
6233
		if (UNMARSHALLING(ps))
6256
			ctr->info.id23 = (SAM_USER_INFO_23 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_23));
6234
			ctr->info.id23 = PRS_ALLOC_MEM( ps, SAM_USER_INFO_23, 1 );
6257
6235
6258
		if (ctr->info.id23 == NULL) {
6236
		if (ctr->info.id23 == NULL) {
6259
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6237
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
Lines 6263-6269 Link Here
6263
		break;
6241
		break;
6264
	case 24:
6242
	case 24:
6265
		if (UNMARSHALLING(ps))
6243
		if (UNMARSHALLING(ps))
6266
			ctr->info.id24 = (SAM_USER_INFO_24 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_24));
6244
			ctr->info.id24 = PRS_ALLOC_MEM( ps, SAM_USER_INFO_24, 1);
6267
6245
6268
		if (ctr->info.id24 == NULL) {
6246
		if (ctr->info.id24 == NULL) {
6269
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6247
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
Lines 6273-6279 Link Here
6273
		break;
6251
		break;
6274
	case 25:
6252
	case 25:
6275
		if (UNMARSHALLING(ps))
6253
		if (UNMARSHALLING(ps))
6276
			ctr->info.id25 = (SAM_USER_INFO_25 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_25));
6254
			ctr->info.id25 = PRS_ALLOC_MEM( ps, SAM_USER_INFO_25, 1 );
6277
6255
6278
		if (ctr->info.id25 == NULL) {
6256
		if (ctr->info.id25 == NULL) {
6279
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6257
			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
Lines 7094-7100 Link Here
7094
	if(!prs_align(ps))
7072
	if(!prs_align(ps))
7095
		return False;
7073
		return False;
7096
7074
7097
	if ((q_u->ctr = (SAM_UNK_CTR *)prs_alloc_mem(ps, sizeof(SAM_UNK_CTR))) == NULL)
7075
	if ((q_u->ctr = PRS_ALLOC_MEM( ps, SAM_UNK_CTR, 1 )) == NULL)
7098
		return False;
7076
		return False;
7099
	
7077
	
7100
	switch (q_u->switch_value) {
7078
	switch (q_u->switch_value) {
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_parse/parse_sec.c (-11 / +11 lines)
Lines 116-122 Link Here
116
	SEC_ACL *dst;
116
	SEC_ACL *dst;
117
	int i;
117
	int i;
118
118
119
	if((dst = (SEC_ACL *)talloc_zero(ctx,sizeof(SEC_ACL))) == NULL)
119
	if((dst = TALLOC_ZERO_P(ctx,SEC_ACL)) == NULL)
120
		return NULL;
120
		return NULL;
121
121
122
	dst->revision = revision;
122
	dst->revision = revision;
Lines 130-136 Link Here
130
	   positive number. */
130
	   positive number. */
131
131
132
	if ((num_aces) && 
132
	if ((num_aces) && 
133
            ((dst->ace = (SEC_ACE *)talloc(ctx, sizeof(SEC_ACE) * num_aces)) 
133
            ((dst->ace = TALLOC_ARRAY(ctx, SEC_ACE,num_aces)) 
134
             == NULL)) {
134
             == NULL)) {
135
		return NULL;
135
		return NULL;
136
	}
136
	}
Lines 185-191 Link Here
185
		/*
185
		/*
186
		 * This is a read and we must allocate the stuct to read into.
186
		 * This is a read and we must allocate the stuct to read into.
187
		 */
187
		 */
188
		if((psa = (SEC_ACL *)prs_alloc_mem(ps, sizeof(SEC_ACL))) == NULL)
188
		if((psa = PRS_ALLOC_MEM( ps, SEC_ACL, 1 )) == NULL)
189
			return False;
189
			return False;
190
		*ppsa = psa;
190
		*ppsa = psa;
191
	}
191
	}
Lines 210-216 Link Here
210
		 * between a non-present DACL (allow all access) and a DACL with no ACE's
210
		 * between a non-present DACL (allow all access) and a DACL with no ACE's
211
		 * (allow no access).
211
		 * (allow no access).
212
		 */
212
		 */
213
		if((psa->ace = (SEC_ACE *)prs_alloc_mem(ps,sizeof(psa->ace[0]) * (psa->num_aces+1))) == NULL)
213
		if((psa->ace = PRS_ALLOC_MEM( ps, SEC_ACE, psa->num_aces+1 )) == NULL)
214
			return False;
214
			return False;
215
	}
215
	}
216
216
Lines 461-467 Link Here
461
  if(!src)
461
  if(!src)
462
    return NULL;
462
    return NULL;
463
463
464
  if((dst = talloc_zero(ctx, sizeof(DOM_SID))) != NULL) {
464
  if((dst = TALLOC_ZERO_P(ctx, DOM_SID)) != NULL) {
465
    sid_copy( dst, src);
465
    sid_copy( dst, src);
466
  }
466
  }
467
467
Lines 481-487 Link Here
481
481
482
	*sd_size = 0;
482
	*sd_size = 0;
483
483
484
	if(( dst = (SEC_DESC *)talloc_zero(ctx, sizeof(SEC_DESC))) == NULL)
484
	if(( dst = TALLOC_ZERO_P(ctx, SEC_DESC)) == NULL)
485
		return NULL;
485
		return NULL;
486
486
487
	dst->revision = revision;
487
	dst->revision = revision;
Lines 604-610 Link Here
604
604
605
	if (psd == NULL) {
605
	if (psd == NULL) {
606
		if(UNMARSHALLING(ps)) {
606
		if(UNMARSHALLING(ps)) {
607
			if((psd = (SEC_DESC *)prs_alloc_mem(ps,sizeof(SEC_DESC))) == NULL)
607
			if((psd = PRS_ALLOC_MEM( ps, SEC_DESC, 1 )) == NULL)
608
				return False;
608
				return False;
609
			*ppsd = psd;
609
			*ppsd = psd;
610
		} else {
610
		} else {
Lines 657-663 Link Here
657
657
658
		if (UNMARSHALLING(ps)) {
658
		if (UNMARSHALLING(ps)) {
659
			/* reading */
659
			/* reading */
660
			if((psd->owner_sid = (DOM_SID *)prs_alloc_mem(ps,sizeof(*psd->owner_sid))) == NULL)
660
			if((psd->owner_sid = PRS_ALLOC_MEM( ps, DOM_SID, 1 )) == NULL)
661
				return False;
661
				return False;
662
		}
662
		}
663
663
Lines 678-684 Link Here
678
678
679
		if (UNMARSHALLING(ps)) {
679
		if (UNMARSHALLING(ps)) {
680
			/* reading */
680
			/* reading */
681
			if((psd->grp_sid = (DOM_SID *)prs_alloc_mem(ps,sizeof(*psd->grp_sid))) == NULL)
681
			if((psd->grp_sid = PRS_ALLOC_MEM( ps, DOM_SID, 1 )) == NULL)
682
				return False;
682
				return False;
683
		}
683
		}
684
684
Lines 726-732 Link Here
726
{
726
{
727
	SEC_DESC_BUF *dst;
727
	SEC_DESC_BUF *dst;
728
728
729
	if((dst = (SEC_DESC_BUF *)talloc_zero(ctx, sizeof(SEC_DESC_BUF))) == NULL)
729
	if((dst = TALLOC_ZERO_P(ctx, SEC_DESC_BUF)) == NULL)
730
		return NULL;
730
		return NULL;
731
731
732
	/* max buffer size (allocated size) */
732
	/* max buffer size (allocated size) */
Lines 772-778 Link Here
772
	psdb = *ppsdb;
772
	psdb = *ppsdb;
773
773
774
	if (UNMARSHALLING(ps) && psdb == NULL) {
774
	if (UNMARSHALLING(ps) && psdb == NULL) {
775
		if((psdb = (SEC_DESC_BUF *)prs_alloc_mem(ps,sizeof(SEC_DESC_BUF))) == NULL)
775
		if((psdb = PRS_ALLOC_MEM( ps, SEC_DESC_BUF, 1 )) == NULL)
776
			return False;
776
			return False;
777
		*ppsdb = psdb;
777
		*ppsdb = psdb;
778
	}
778
	}
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_parse/parse_spoolss.c (-43 / +40 lines)
Lines 266-272 Link Here
266
266
267
	/* reading */
267
	/* reading */
268
	if (UNMARSHALLING(ps))
268
	if (UNMARSHALLING(ps))
269
		if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
269
		if((ctr->type=PRS_ALLOC_MEM( ps, SPOOL_NOTIFY_OPTION_TYPE, ctr->count )) == NULL)
270
			return False;
270
			return False;
271
		
271
		
272
	/* the option type struct */
272
	/* the option type struct */
Lines 416-422 Link Here
416
416
417
			/* Tallocate memory for string */
417
			/* Tallocate memory for string */
418
418
419
			data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
419
			data->notify_data.data.string = PRS_ALLOC_MEM( ps, uint16, x );
420
			if (!data->notify_data.data.string) 
420
			if (!data->notify_data.data.string) 
421
				return False;
421
				return False;
422
422
Lines 582-588 Link Here
582
	depth++;
582
	depth++;
583
583
584
	if (UNMARSHALLING(ps)) {
584
	if (UNMARSHALLING(ps)) {
585
		devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
585
		devmode->devicename.buffer = PRS_ALLOC_MEM( ps, uint16, 32 );
586
		if (devmode->devicename.buffer == NULL)
586
		if (devmode->devicename.buffer == NULL)
587
			return False;
587
			return False;
588
	}
588
	}
Lines 646-652 Link Here
646
		return False;
646
		return False;
647
647
648
	if (UNMARSHALLING(ps)) {
648
	if (UNMARSHALLING(ps)) {
649
		devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
649
		devmode->formname.buffer = PRS_ALLOC_MEM( ps, uint16, 32 );
650
		if (devmode->formname.buffer == NULL)
650
		if (devmode->formname.buffer == NULL)
651
			return False;
651
			return False;
652
	}
652
	}
Lines 711-717 Link Here
711
711
712
	if (devmode->driverextra!=0) {
712
	if (devmode->driverextra!=0) {
713
		if (UNMARSHALLING(ps)) {
713
		if (UNMARSHALLING(ps)) {
714
			devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
714
			devmode->private= PRS_ALLOC_MEM( ps, uint8, devmode->driverextra );
715
			if(devmode->private == NULL)
715
			if(devmode->private == NULL)
716
				return False;
716
				return False;
717
			DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra)); 
717
			DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra)); 
Lines 757-763 Link Here
757
	/* so we have a DEVICEMODE to follow */		
757
	/* so we have a DEVICEMODE to follow */		
758
	if (UNMARSHALLING(ps)) {
758
	if (UNMARSHALLING(ps)) {
759
		DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
759
		DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
760
		dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
760
		dm_c->devmode= PRS_ALLOC_MEM( ps, DEVICEMODE, 1 );
761
		if(dm_c->devmode == NULL)
761
		if(dm_c->devmode == NULL)
762
			return False;
762
			return False;
763
	}
763
	}
Lines 911-917 Link Here
911
	SPOOL_PRINTER_INFO_LEVEL_2 *inf;
911
	SPOOL_PRINTER_INFO_LEVEL_2 *inf;
912
912
913
	/* allocate the necessary memory */
913
	/* allocate the necessary memory */
914
	if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2)))) {
914
	if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2))) {
915
		DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
915
		DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
916
		return False;
916
		return False;
917
	}
917
	}
Lines 1206-1212 Link Here
1206
		return False;
1206
		return False;
1207
	
1207
	
1208
	if (UNMARSHALLING(ps) && r_u->size) {
1208
	if (UNMARSHALLING(ps) && r_u->size) {
1209
		r_u->data = prs_alloc_mem(ps, r_u->size);
1209
		r_u->data = PRS_ALLOC_MEM( ps, unsigned char, r_u->size );
1210
		if(!r_u->data)
1210
		if(!r_u->data)
1211
			return False;
1211
			return False;
1212
	}
1212
	}
Lines 1589-1595 Link Here
1589
	if (q_u->buffer_size!=0)
1589
	if (q_u->buffer_size!=0)
1590
	{
1590
	{
1591
		if (UNMARSHALLING(ps))
1591
		if (UNMARSHALLING(ps))
1592
			q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
1592
			q_u->buffer=PRS_ALLOC_MEM( ps, uint8, q_u->buffer_size );
1593
		if(q_u->buffer == NULL)
1593
		if(q_u->buffer == NULL)
1594
			return False;	
1594
			return False;	
1595
		if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
1595
		if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
Lines 1656-1662 Link Here
1656
	if (q_u->option_ptr!=0) {
1656
	if (q_u->option_ptr!=0) {
1657
	
1657
	
1658
		if (UNMARSHALLING(ps))
1658
		if (UNMARSHALLING(ps))
1659
			if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1659
			if((q_u->option= PRS_ALLOC_MEM( ps, SPOOL_NOTIFY_OPTION, 1 )) == NULL)
1660
				return False;
1660
				return False;
1661
	
1661
	
1662
		if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1662
		if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
Lines 1707-1713 Link Here
1707
	if (q_u->option_ptr!=0) {
1707
	if (q_u->option_ptr!=0) {
1708
	
1708
	
1709
		if (UNMARSHALLING(ps))
1709
		if (UNMARSHALLING(ps))
1710
			if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1710
			if((q_u->option= PRS_ALLOC_MEM( ps, SPOOL_NOTIFY_OPTION, 1 )) == NULL)
1711
				return False;
1711
				return False;
1712
	
1712
	
1713
		if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1713
		if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
Lines 1930-1936 Link Here
1930
1930
1931
			/* Yes this should be malloc not talloc. Don't change. */
1931
			/* Yes this should be malloc not talloc. Don't change. */
1932
1932
1933
			chaine.buffer = malloc((q-p+1)*sizeof(uint16));
1933
			chaine.buffer = SMB_MALLOC_ARRAY( uint16, q-p+1 );
1934
			if (chaine.buffer == NULL)
1934
			if (chaine.buffer == NULL)
1935
				return False;
1935
				return False;
1936
1936
Lines 1999-2005 Link Here
1999
1999
2000
				/* Yes this should be realloc - it's freed below. JRA */
2000
				/* Yes this should be realloc - it's freed below. JRA */
2001
2001
2002
				if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
2002
				if((tc2=SMB_REALLOC_ARRAY(chaine2, uint16, l_chaine2+l_chaine+2 )) == NULL) {
2003
					SAFE_FREE(chaine2);
2003
					SAFE_FREE(chaine2);
2004
					return False;
2004
					return False;
2005
				}
2005
				}
Lines 2015-2021 Link Here
2015
		if (chaine2)
2015
		if (chaine2)
2016
		{
2016
		{
2017
			chaine2[l_chaine2] = '\0';
2017
			chaine2[l_chaine2] = '\0';
2018
			*string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
2018
			*string=(uint16 *)TALLOC_MEMDUP(prs_get_mem_context(ps),chaine2,realloc_size);
2019
			SAFE_FREE(chaine2);
2019
			SAFE_FREE(chaine2);
2020
		}
2020
		}
2021
2021
Lines 2143-2149 Link Here
2143
			return False;
2143
			return False;
2144
2144
2145
		/* read the string */
2145
		/* read the string */
2146
		if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
2146
		if((*devmode= PRS_ALLOC_MEM( ps, DEVICEMODE, 1 )) == NULL)
2147
			return False;
2147
			return False;
2148
		if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2148
		if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2149
			return False;
2149
			return False;
Lines 2794-2800 Link Here
2794
	depth++;
2794
	depth++;
2795
	
2795
	
2796
	if (UNMARSHALLING(ps))
2796
	if (UNMARSHALLING(ps))
2797
		buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
2797
		buffer = *pp_buffer = PRS_ALLOC_MEM( ps, NEW_BUFFER, 1 );
2798
2798
2799
	if (buffer == NULL)
2799
	if (buffer == NULL)
2800
		return False;
2800
		return False;
Lines 3839-3845 Link Here
3839
		
3839
		
3840
		make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
3840
		make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
3841
#if 1	/* JERRY TEST */
3841
#if 1	/* JERRY TEST */
3842
		q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
3842
		q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF);
3843
		if (!q_u->secdesc_ctr)
3843
		if (!q_u->secdesc_ctr)
3844
			return False;
3844
			return False;
3845
		q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
3845
		q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
Lines 4642-4648 Link Here
4642
		case 1:
4642
		case 1:
4643
		{
4643
		{
4644
			if (UNMARSHALLING(ps)) {
4644
			if (UNMARSHALLING(ps)) {
4645
				if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
4645
				if ((il->info_1= PRS_ALLOC_MEM( ps, SPOOL_PRINTER_INFO_LEVEL_1, 1 )) == NULL)
4646
					return False;
4646
					return False;
4647
			}
4647
			}
4648
			if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
4648
			if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
Lines 4655-4661 Link Here
4655
		 */	
4655
		 */	
4656
		case 2:
4656
		case 2:
4657
			if (UNMARSHALLING(ps)) {
4657
			if (UNMARSHALLING(ps)) {
4658
				if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
4658
				if ((il->info_2= PRS_ALLOC_MEM( ps,  SPOOL_PRINTER_INFO_LEVEL_2, 1 )) == NULL)
4659
					return False;
4659
					return False;
4660
			}
4660
			}
4661
			if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
4661
			if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
Lines 4665-4671 Link Here
4665
		case 3:
4665
		case 3:
4666
		{
4666
		{
4667
			if (UNMARSHALLING(ps)) {
4667
			if (UNMARSHALLING(ps)) {
4668
				if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
4668
				if ((il->info_3= PRS_ALLOC_MEM( ps, SPOOL_PRINTER_INFO_LEVEL_3, 1 )) == NULL)
4669
					return False;
4669
					return False;
4670
			}
4670
			}
4671
			if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
4671
			if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
Lines 4772-4778 Link Here
4772
		
4772
		
4773
	/* reading */
4773
	/* reading */
4774
	if (UNMARSHALLING(ps)) {
4774
	if (UNMARSHALLING(ps)) {
4775
		il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
4775
		il= PRS_ALLOC_MEM( ps, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3, 1);
4776
		if(il == NULL)
4776
		if(il == NULL)
4777
			return False;
4777
			return False;
4778
		*q_u=il;
4778
		*q_u=il;
Lines 4850-4856 Link Here
4850
		
4850
		
4851
	/* reading */
4851
	/* reading */
4852
	if (UNMARSHALLING(ps)) {
4852
	if (UNMARSHALLING(ps)) {
4853
		il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
4853
		il= PRS_ALLOC_MEM( ps, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6, 1 );
4854
		if(il == NULL)
4854
		if(il == NULL)
4855
			return False;
4855
			return False;
4856
		*q_u=il;
4856
		*q_u=il;
Lines 5009-5015 Link Here
5009
	while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
5009
	while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
5010
		unistr_to_dos(f, src, sizeof(f)-1);
5010
		unistr_to_dos(f, src, sizeof(f)-1);
5011
		src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
5011
		src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
5012
		tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
5012
		tar = SMB_REALLOC_ARRAY( *ar, fstring, n+2 );
5013
		if (!tar)
5013
		if (!tar)
5014
			return False;
5014
			return False;
5015
		else
5015
		else
Lines 5123-5129 Link Here
5123
	BOOL		null_char = False;
5123
	BOOL		null_char = False;
5124
	SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
5124
	SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
5125
5125
5126
	if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
5126
	if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)TALLOC_ZERO_P(mem_ctx, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3)))
5127
		return False;
5127
		return False;
5128
	
5128
	
5129
	inf->cversion	= info3->version;
5129
	inf->cversion	= info3->version;
Lines 5186-5193 Link Here
5186
{
5186
{
5187
5187
5188
	buf5->buf_len = len;
5188
	buf5->buf_len = len;
5189
	if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
5189
	if((buf5->buffer=(uint16*)TALLOC_MEMDUP(mem_ctx, src, sizeof(uint16)*len)) == NULL) {
5190
	{
5191
		DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
5190
		DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
5192
		return False;
5191
		return False;
5193
	}
5192
	}
Lines 5249-5255 Link Here
5249
	
5248
	
5250
	if (*asc==NULL)
5249
	if (*asc==NULL)
5251
	{
5250
	{
5252
		*asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
5251
		*asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
5253
		if(*asc == NULL)
5252
		if(*asc == NULL)
5254
			return False;
5253
			return False;
5255
		ZERO_STRUCTP(*asc);
5254
		ZERO_STRUCTP(*asc);
Lines 5296-5302 Link Here
5296
	
5295
	
5297
	if (*asc==NULL)
5296
	if (*asc==NULL)
5298
	{
5297
	{
5299
		*asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
5298
		*asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
5300
		if(*asc == NULL)
5299
		if(*asc == NULL)
5301
			return False;
5300
			return False;
5302
		ZERO_STRUCTP(*asc);
5301
		ZERO_STRUCTP(*asc);
Lines 5349-5355 Link Here
5349
	if (*asc==NULL) {
5348
	if (*asc==NULL) {
5350
		DEBUGADD(8,("allocating memory\n"));
5349
		DEBUGADD(8,("allocating memory\n"));
5351
5350
5352
		*asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
5351
		*asc=SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL_2);
5353
		if(*asc == NULL)
5352
		if(*asc == NULL)
5354
			return False;
5353
			return False;
5355
		ZERO_STRUCTP(*asc);
5354
		ZERO_STRUCTP(*asc);
Lines 5744-5750 Link Here
5744
		return False;
5743
		return False;
5745
5744
5746
	if (UNMARSHALLING(ps) && r_u->valuesize) {
5745
	if (UNMARSHALLING(ps) && r_u->valuesize) {
5747
		r_u->value = (uint16 *)prs_alloc_mem(ps, r_u->valuesize * 2);
5746
		r_u->value = PRS_ALLOC_MEM( ps, uint16, r_u->valuesize );
5748
		if (!r_u->value) {
5747
		if (!r_u->value) {
5749
			DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata value\n"));
5748
			DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata value\n"));
5750
			return False;
5749
			return False;
Lines 5767-5773 Link Here
5767
		return False;
5766
		return False;
5768
5767
5769
	if (UNMARSHALLING(ps) && r_u->datasize) {
5768
	if (UNMARSHALLING(ps) && r_u->datasize) {
5770
		r_u->data = (uint8 *)prs_alloc_mem(ps, r_u->datasize);
5769
		r_u->data = PRS_ALLOC_MEM( ps, uint8, r_u->datasize );
5771
		if (!r_u->data) {
5770
		if (!r_u->data) {
5772
			DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata data\n"));
5771
			DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata data\n"));
5773
			return False;
5772
			return False;
Lines 5837-5843 Link Here
5837
5836
5838
	init_unistr2(&tmp, data, strlen(data)+1);
5837
	init_unistr2(&tmp, data, strlen(data)+1);
5839
	q_u->max_len = q_u->real_len = tmp.uni_max_len*2;
5838
	q_u->max_len = q_u->real_len = tmp.uni_max_len*2;
5840
	q_u->data = talloc(ctx, q_u->real_len);
5839
	q_u->data = TALLOC(ctx, q_u->real_len);
5841
	memcpy(q_u->data, tmp.buffer, q_u->real_len);
5840
	memcpy(q_u->data, tmp.buffer, q_u->real_len);
5842
	
5841
	
5843
	return True;
5842
	return True;
Lines 5874-5880 Link Here
5874
		case REG_MULTI_SZ:
5873
		case REG_MULTI_SZ:
5875
            if (q_u->max_len) {
5874
            if (q_u->max_len) {
5876
                if (UNMARSHALLING(ps))
5875
                if (UNMARSHALLING(ps))
5877
    				q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
5876
    				q_u->data= PRS_ALLOC_MEM( ps, uint8, q_u->max_len );
5878
    			if(q_u->data == NULL)
5877
    			if(q_u->data == NULL)
5879
    				return False;
5878
    				return False;
5880
    			if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
5879
    			if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
Lines 5958-5964 Link Here
5958
5957
5959
	if (*param == NULL)
5958
	if (*param == NULL)
5960
	{
5959
	{
5961
		*param=(NT_PRINTER_PARAM *)malloc(sizeof(NT_PRINTER_PARAM));
5960
		*param=SMB_MALLOC_P(NT_PRINTER_PARAM);
5962
		if(*param == NULL)
5961
		if(*param == NULL)
5963
			return False;
5962
			return False;
5964
		memset((char *)*param, '\0', sizeof(NT_PRINTER_PARAM));
5963
		memset((char *)*param, '\0', sizeof(NT_PRINTER_PARAM));
Lines 5973-5979 Link Here
5973
	(*param)->data_len=len;
5972
	(*param)->data_len=len;
5974
	
5973
	
5975
	if (len) {
5974
	if (len) {
5976
		(*param)->data=(uint8 *)malloc(len * sizeof(uint8));
5975
		(*param)->data=SMB_MALLOC_ARRAY( uint8, len );
5977
		if((*param)->data == NULL)
5976
		if((*param)->data == NULL)
5978
			return False;
5977
			return False;
5979
		memcpy((*param)->data, data, len);
5978
		memcpy((*param)->data, data, len);
Lines 6464-6470 Link Here
6464
		if (src->size != POINTER) 
6463
		if (src->size != POINTER) 
6465
			continue;
6464
			continue;
6466
		len = src->notify_data.data.length;
6465
		len = src->notify_data.data.length;
6467
		s = malloc(sizeof(uint16)*len);
6466
		s = SMB_MALLOC_ARRAY(uint16, len );
6468
		if (s == NULL) {
6467
		if (s == NULL) {
6469
			DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
6468
			DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
6470
			return False;
6469
			return False;
Lines 6493-6499 Link Here
6493
	
6492
	
6494
	if (dst->count) 
6493
	if (dst->count) 
6495
	{
6494
	{
6496
		dst->data = malloc(dst->count * sizeof(SPOOL_NOTIFY_INFO_DATA));
6495
		dst->data = SMB_MALLOC_ARRAY( SPOOL_NOTIFY_INFO_DATA, dst->count );
6497
		
6496
		
6498
		DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
6497
		DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
6499
			dst->count));
6498
			dst->count));
Lines 6663-6669 Link Here
6663
		return False;
6662
		return False;
6664
	
6663
	
6665
	if (UNMARSHALLING(ps) && r_u->size) {
6664
	if (UNMARSHALLING(ps) && r_u->size) {
6666
		r_u->data = prs_alloc_mem(ps, r_u->size);
6665
		r_u->data = PRS_ALLOC_MEM( ps, unsigned char, r_u->size );
6667
		if(!r_u->data)
6666
		if(!r_u->data)
6668
			return False;
6667
			return False;
6669
	}
6668
	}
Lines 6721-6727 Link Here
6721
		case 0x7:
6720
		case 0x7:
6722
			if (q_u->max_len) {
6721
			if (q_u->max_len) {
6723
				if (UNMARSHALLING(ps))
6722
				if (UNMARSHALLING(ps))
6724
    					q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
6723
    					q_u->data= PRS_ALLOC_MEM( ps, uint8, q_u->max_len );
6725
    				if(q_u->data == NULL)
6724
    				if(q_u->data == NULL)
6726
    					return False;
6725
    					return False;
6727
    				if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
6726
    				if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
Lines 6861-6868 Link Here
6861
	/* first loop to write basic enum_value information */
6860
	/* first loop to write basic enum_value information */
6862
	
6861
	
6863
	if (UNMARSHALLING(ps)) {
6862
	if (UNMARSHALLING(ps)) {
6864
		ctr->values = (PRINTER_ENUM_VALUES *)prs_alloc_mem(
6863
		ctr->values = PRS_ALLOC_MEM( ps, PRINTER_ENUM_VALUES, ctr->size_of_array );
6865
			ps, ctr->size_of_array * sizeof(PRINTER_ENUM_VALUES));
6866
		if (!ctr->values)
6864
		if (!ctr->values)
6867
			return False;
6865
			return False;
6868
	}
6866
	}
Lines 6902-6909 Link Here
6902
			return False;
6900
			return False;
6903
		
6901
		
6904
		if (UNMARSHALLING(ps)) {
6902
		if (UNMARSHALLING(ps)) {
6905
			ctr->values[i].data = (uint8 *)prs_alloc_mem(
6903
			ctr->values[i].data = PRS_ALLOC_MEM( ps, uint8, ctr->values[i].data_len );
6906
				ps, ctr->values[i].data_len);
6907
			if (!ctr->values[i].data)
6904
			if (!ctr->values[i].data)
6908
				return False;
6905
				return False;
6909
		}
6906
		}
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_parse/parse_srv.c (-10 / +8 lines)
Lines 541-547 Link Here
541
		int i;
541
		int i;
542
542
543
		if (UNMARSHALLING(ps)) {
543
		if (UNMARSHALLING(ps)) {
544
			if (!(info1 = (SRV_SHARE_INFO_1 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_SHARE_INFO_1))))
544
			if (!(info1 = PRS_ALLOC_MEM( ps, SRV_SHARE_INFO_1, num_entries )))
545
				return False;
545
				return False;
546
			ctr->share.info1 = info1;
546
			ctr->share.info1 = info1;
547
		}
547
		}
Lines 566-572 Link Here
566
		int i;
566
		int i;
567
567
568
		if (UNMARSHALLING(ps)) {
568
		if (UNMARSHALLING(ps)) {
569
			if (!(info2 = (SRV_SHARE_INFO_2 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_2))))
569
			if (!(info2 = PRS_ALLOC_MEM( ps, SRV_SHARE_INFO_2, num_entries )))
570
				return False;
570
				return False;
571
			ctr->share.info2 = info2;
571
			ctr->share.info2 = info2;
572
		}
572
		}
Lines 591-598 Link Here
591
		int i;
591
		int i;
592
592
593
		if (UNMARSHALLING(ps)) {
593
		if (UNMARSHALLING(ps)) {
594
			if (!(info501 = (SRV_SHARE_INFO_501 *) prs_alloc_mem(ps, num_entries *
594
			if (!(info501 = PRS_ALLOC_MEM( ps, SRV_SHARE_INFO_501, num_entries )))
595
					sizeof (SRV_SHARE_INFO_501))))
596
				return False;
595
				return False;
597
			ctr->share.info501 = info501;
596
			ctr->share.info501 = info501;
598
		}
597
		}
Lines 617-623 Link Here
617
		int i;
616
		int i;
618
617
619
		if (UNMARSHALLING(ps)) {
618
		if (UNMARSHALLING(ps)) {
620
			if (!(info502 = (SRV_SHARE_INFO_502 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_502))))
619
			if (!(info502 = PRS_ALLOC_MEM( ps, SRV_SHARE_INFO_502, num_entries )))
621
				return False;
620
				return False;
622
			ctr->share.info502 = info502;
621
			ctr->share.info502 = info502;
623
		}
622
		}
Lines 1289-1295 Link Here
1289
	depth++;
1288
	depth++;
1290
1289
1291
	if(UNMARSHALLING(ps)) {
1290
	if(UNMARSHALLING(ps)) {
1292
		ctr = *pp_ctr = (SRV_SESS_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_SESS_INFO_CTR));
1291
		ctr = *pp_ctr = PRS_ALLOC_MEM(ps, SRV_SESS_INFO_CTR, 1 );
1293
		if (ctr == NULL)
1292
		if (ctr == NULL)
1294
			return False;
1293
			return False;
1295
	}
1294
	}
Lines 1654-1660 Link Here
1654
	depth++;
1653
	depth++;
1655
1654
1656
	if (UNMARSHALLING(ps)) {
1655
	if (UNMARSHALLING(ps)) {
1657
		ctr = *pp_ctr = (SRV_CONN_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_CONN_INFO_CTR));
1656
		ctr = *pp_ctr = PRS_ALLOC_MEM( ps, SRV_CONN_INFO_CTR, 1 );
1658
		if (ctr == NULL)
1657
		if (ctr == NULL)
1659
			return False;
1658
			return False;
1660
	}
1659
	}
Lines 1933-1939 Link Here
1933
	SRV_FILE_INFO_CTR *ctr = *pp_ctr;
1932
	SRV_FILE_INFO_CTR *ctr = *pp_ctr;
1934
1933
1935
	if (UNMARSHALLING(ps)) {
1934
	if (UNMARSHALLING(ps)) {
1936
		ctr = *pp_ctr = (SRV_FILE_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_FILE_INFO_CTR));
1935
		ctr = *pp_ctr = PRS_ALLOC_MEM(ps, SRV_FILE_INFO_CTR, 1);
1937
		if (ctr == NULL)
1936
		if (ctr == NULL)
1938
			return False;
1937
			return False;
1939
	}
1938
	}
Lines 2407-2414 Link Here
2407
		return False;
2406
		return False;
2408
2407
2409
	if (UNMARSHALLING(ps)) {
2408
	if (UNMARSHALLING(ps)) {
2410
		q_n->ctr = (SRV_INFO_CTR *)
2409
		q_n->ctr = PRS_ALLOC_MEM( ps, SRV_INFO_CTR, 1 );
2411
			prs_alloc_mem(ps, sizeof(SRV_INFO_CTR));
2412
2410
2413
		if (!q_n->ctr)
2411
		if (!q_n->ctr)
2414
			return False;
2412
			return False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_dfs_nt.c (-8 / +6 lines)
Lines 82-89 Link Here
82
  else
82
  else
83
    jn.referral_count = 1;
83
    jn.referral_count = 1;
84
84
85
  jn.referral_list = (struct referral*) talloc(p->mem_ctx, jn.referral_count 
85
  jn.referral_list = TALLOC_ARRAY(p->mem_ctx, struct referral, jn.referral_count );
86
					       * sizeof(struct referral));
87
86
88
  if(jn.referral_list == NULL)
87
  if(jn.referral_list == NULL)
89
    {
88
    {
Lines 245-252 Link Here
245
      dfs3[i].ptr_storages = 1;
244
      dfs3[i].ptr_storages = 1;
246
     
245
     
247
      /* also enumerate the storages */
246
      /* also enumerate the storages */
248
      dfs3[i].storages = (DFS_STORAGE_INFO*) talloc(ctx, j[i].referral_count * 
247
      dfs3[i].storages = TALLOC_ARRAY(ctx, DFS_STORAGE_INFO, j[i].referral_count);
249
						    sizeof(DFS_STORAGE_INFO));
250
      if (!dfs3[i].storages)
248
      if (!dfs3[i].storages)
251
        return False;
249
        return False;
252
250
Lines 288-294 Link Here
288
    case 1:
286
    case 1:
289
      {
287
      {
290
	DFS_INFO_1* dfs1;
288
	DFS_INFO_1* dfs1;
291
	dfs1 = (DFS_INFO_1*) talloc(ctx, num_jn * sizeof(DFS_INFO_1));
289
	dfs1 = TALLOC_ARRAY(ctx, DFS_INFO_1, num_jn);
292
	if (!dfs1)
290
	if (!dfs1)
293
		return WERR_NOMEM;
291
		return WERR_NOMEM;
294
	init_reply_dfs_info_1(jn, dfs1, num_jn);
292
	init_reply_dfs_info_1(jn, dfs1, num_jn);
Lines 298-304 Link Here
298
    case 2:
296
    case 2:
299
      {
297
      {
300
	DFS_INFO_2* dfs2;
298
	DFS_INFO_2* dfs2;
301
	dfs2 = (DFS_INFO_2*) talloc(ctx, num_jn * sizeof(DFS_INFO_2));
299
	dfs2 = TALLOC_ARRAY(ctx, DFS_INFO_2, num_jn);
302
	if (!dfs2)
300
	if (!dfs2)
303
		return WERR_NOMEM;
301
		return WERR_NOMEM;
304
	init_reply_dfs_info_2(jn, dfs2, num_jn);
302
	init_reply_dfs_info_2(jn, dfs2, num_jn);
Lines 308-314 Link Here
308
    case 3:
306
    case 3:
309
      {
307
      {
310
	DFS_INFO_3* dfs3;
308
	DFS_INFO_3* dfs3;
311
	dfs3 = (DFS_INFO_3*) talloc(ctx, num_jn * sizeof(DFS_INFO_3));
309
	dfs3 = TALLOC_ARRAY(ctx, DFS_INFO_3, num_jn);
312
	if (!dfs3)
310
	if (!dfs3)
313
		return WERR_NOMEM;
311
		return WERR_NOMEM;
314
	init_reply_dfs_info_3(ctx, jn, dfs3, num_jn);
312
	init_reply_dfs_info_3(ctx, jn, dfs3, num_jn);
Lines 338-344 Link Here
338
  r_u->reshnd.ptr_hnd = 1;
336
  r_u->reshnd.ptr_hnd = 1;
339
  r_u->reshnd.handle = num_jn;
337
  r_u->reshnd.handle = num_jn;
340
  
338
  
341
  r_u->ctr = (DFS_INFO_CTR*)talloc(p->mem_ctx, sizeof(DFS_INFO_CTR));
339
  r_u->ctr = TALLOC_P(p->mem_ctx, DFS_INFO_CTR);
342
  if (!r_u->ctr)
340
  if (!r_u->ctr)
343
    return WERR_NOMEM;
341
    return WERR_NOMEM;
344
  ZERO_STRUCTP(r_u->ctr);
342
  ZERO_STRUCTP(r_u->ctr);
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_lsa_hnd.c (-2 / +2 lines)
Lines 68-74 Link Here
68
		 * Create list.
68
		 * Create list.
69
		 */
69
		 */
70
70
71
		if ((hl = (struct handle_list *)malloc(sizeof(struct handle_list))) == NULL)
71
		if ((hl = SMB_MALLOC_P(struct handle_list)) == NULL)
72
			return False;
72
			return False;
73
		ZERO_STRUCTP(hl);
73
		ZERO_STRUCTP(hl);
74
74
Lines 110-116 Link Here
110
		return False;
110
		return False;
111
	}
111
	}
112
112
113
	pol = (struct policy *)malloc(sizeof(*p));
113
	pol = SMB_MALLOC_P(struct policy);
114
	if (!pol) {
114
	if (!pol) {
115
		DEBUG(0,("create_policy_hnd: ERROR: out of memory!\n"));
115
		DEBUG(0,("create_policy_hnd: ERROR: out of memory!\n"));
116
		return False;
116
		return False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_lsa_nt.c (-11 / +9 lines)
Lines 218-231 Link Here
218
	/* Allocate memory for list of names */
218
	/* Allocate memory for list of names */
219
219
220
	if (num_entries > 0) {
220
	if (num_entries > 0) {
221
		if (!(trn->name = (LSA_TRANS_NAME *)talloc(ctx, sizeof(LSA_TRANS_NAME) *
221
		if (!(trn->name = TALLOC_ARRAY(ctx, LSA_TRANS_NAME, num_entries))) {
222
							  num_entries))) {
223
			DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
222
			DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
224
			return;
223
			return;
225
		}
224
		}
226
225
227
		if (!(trn->uni_name = (UNISTR2 *)talloc(ctx, sizeof(UNISTR2) * 
226
		if (!(trn->uni_name = TALLOC_ARRAY(ctx, UNISTR2, num_entries))) {
228
							num_entries))) {
229
			DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
227
			DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
230
			return;
228
			return;
231
		}
229
		}
Lines 385-391 Link Here
385
			info->id2.auditing_enabled = 1;
383
			info->id2.auditing_enabled = 1;
386
			info->id2.count1 = 7;
384
			info->id2.count1 = 7;
387
			info->id2.count2 = 7;
385
			info->id2.count2 = 7;
388
			if ((info->id2.auditsettings = (uint32 *)talloc(p->mem_ctx,7*sizeof(uint32))) == NULL)
386
			if ((info->id2.auditsettings = TALLOC_ARRAY(p->mem_ctx,uint32, 7)) == NULL)
389
				return NT_STATUS_NO_MEMORY;
387
				return NT_STATUS_NO_MEMORY;
390
			for (i = 0; i < 7; i++)
388
			for (i = 0; i < 7; i++)
391
				info->id2.auditsettings[i] = 3;
389
				info->id2.auditsettings[i] = 3;
Lines 482-489 Link Here
482
	LSA_TRANS_NAME_ENUM *names = NULL;
480
	LSA_TRANS_NAME_ENUM *names = NULL;
483
	uint32 mapped_count = 0;
481
	uint32 mapped_count = 0;
484
482
485
	ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
483
	ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
486
	names = (LSA_TRANS_NAME_ENUM *)talloc_zero(p->mem_ctx, sizeof(LSA_TRANS_NAME_ENUM));
484
	names = TALLOC_ZERO_P(p->mem_ctx, LSA_TRANS_NAME_ENUM);
487
485
488
	if (!find_policy_by_hnd(p, &q_u->pol, NULL))
486
	if (!find_policy_by_hnd(p, &q_u->pol, NULL))
489
		r_u->status = NT_STATUS_INVALID_HANDLE;
487
		r_u->status = NT_STATUS_INVALID_HANDLE;
Lines 510-517 Link Here
510
	DOM_RID2 *rids;
508
	DOM_RID2 *rids;
511
	uint32 mapped_count = 0;
509
	uint32 mapped_count = 0;
512
510
513
	ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
511
	ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
514
	rids = (DOM_RID2 *)talloc_zero(p->mem_ctx, sizeof(DOM_RID2)*MAX_LOOKUP_SIDS);
512
	rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID2, MAX_LOOKUP_SIDS);
515
513
516
	if (!find_policy_by_hnd(p, &q_u->pol, NULL))
514
	if (!find_policy_by_hnd(p, &q_u->pol, NULL))
517
		r_u->status = NT_STATUS_INVALID_HANDLE;
515
		r_u->status = NT_STATUS_INVALID_HANDLE;
Lines 566-572 Link Here
566
	if (enum_context >= PRIV_ALL_INDEX)
564
	if (enum_context >= PRIV_ALL_INDEX)
567
		return NT_STATUS_UNABLE_TO_FREE_VM;
565
		return NT_STATUS_UNABLE_TO_FREE_VM;
568
566
569
	entries = (LSA_PRIV_ENTRY *)talloc_zero(p->mem_ctx, sizeof(LSA_PRIV_ENTRY) * (PRIV_ALL_INDEX-enum_context));
567
	entries = TALLOC_ZERO_ARRAY(p->mem_ctx, LSA_PRIV_ENTRY, PRIV_ALL_INDEX-enum_context);
570
	if (entries==NULL)
568
	if (entries==NULL)
571
		return NT_STATUS_NO_MEMORY;
569
		return NT_STATUS_NO_MEMORY;
572
570
Lines 663-669 Link Here
663
		return NT_STATUS_INVALID_HANDLE;
661
		return NT_STATUS_INVALID_HANDLE;
664
662
665
	/* associate the user/group SID with the (unique) handle. */
663
	/* associate the user/group SID with the (unique) handle. */
666
	if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
664
	if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
667
		return NT_STATUS_NO_MEMORY;
665
		return NT_STATUS_NO_MEMORY;
668
666
669
	ZERO_STRUCTP(info);
667
	ZERO_STRUCTP(info);
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_netlog_nt.c (-1 / +1 lines)
Lines 573-579 Link Here
573
	BOOL ret;
573
	BOOL ret;
574
	uint16 acct_ctrl;
574
	uint16 acct_ctrl;
575
   
575
   
576
	usr_info = (NET_USER_INFO_3 *)talloc(p->mem_ctx, sizeof(NET_USER_INFO_3));
576
	usr_info = TALLOC_P(p->mem_ctx, NET_USER_INFO_3);
577
	if (!usr_info)
577
	if (!usr_info)
578
		return NT_STATUS_NO_MEMORY;
578
		return NT_STATUS_NO_MEMORY;
579
	ZERO_STRUCTP(usr_info);
579
	ZERO_STRUCTP(usr_info);
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_pipe.c (-1 / +1 lines)
Lines 1260-1266 Link Here
1260
			p->in_data.data.data_offset;
1260
			p->in_data.data.data_offset;
1261
		char *data;
1261
		char *data;
1262
1262
1263
		data = malloc(data_len);
1263
		data = SMB_MALLOC(data_len);
1264
1264
1265
		DEBUG(10, ("api_rpcTNP: rpc input buffer underflow (parse error?)\n"));
1265
		DEBUG(10, ("api_rpcTNP: rpc input buffer underflow (parse error?)\n"));
1266
		if (data) {
1266
		if (data) {
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_pipe_hnd.c (-1 / +1 lines)
Lines 169-175 Link Here
169
	for (p = Pipes; p; p = p->next)
169
	for (p = Pipes; p; p = p->next)
170
		DEBUG(5,("open_rpc_pipe_p: name %s pnum=%x\n", p->name, p->pnum));  
170
		DEBUG(5,("open_rpc_pipe_p: name %s pnum=%x\n", p->name, p->pnum));  
171
171
172
	p = (pipes_struct *)malloc(sizeof(*p));
172
	p = SMB_MALLOC_P(pipes_struct);
173
173
174
	if (!p)
174
	if (!p)
175
		return NULL;
175
		return NULL;
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_reg_nt.c (-3 / +3 lines)
Lines 92-98 Link Here
92
	    !strequal(name, "System\\CurrentControlSet\\services\\Netlogon\\parameters\\"))
92
	    !strequal(name, "System\\CurrentControlSet\\services\\Netlogon\\parameters\\"))
93
			return NT_STATUS_ACCESS_DENIED;
93
			return NT_STATUS_ACCESS_DENIED;
94
94
95
	if ((info = (struct reg_info *)malloc(sizeof(struct reg_info))) == NULL)
95
	if ((info = SMB_MALLOC_P(struct reg_info)) == NULL)
96
		return NT_STATUS_NO_MEMORY;
96
		return NT_STATUS_NO_MEMORY;
97
97
98
	ZERO_STRUCTP(info);
98
	ZERO_STRUCTP(info);
Lines 131-138 Link Here
131
131
132
	DEBUG(5,("reg_info: checking key: %s\n", name));
132
	DEBUG(5,("reg_info: checking key: %s\n", name));
133
133
134
	uni_key = (UNISTR2 *)talloc_zero(p->mem_ctx, sizeof(UNISTR2));
134
	uni_key = TALLOC_ZERO_P(p->mem_ctx, UNISTR2);
135
	buf = (BUFFER2 *)talloc_zero(p->mem_ctx, sizeof(BUFFER2));
135
	buf = TALLOC_ZERO_P(p->mem_ctx, BUFFER2);
136
136
137
	if (!uni_key || !buf)
137
	if (!uni_key || !buf)
138
		return NT_STATUS_NO_MEMORY;
138
		return NT_STATUS_NO_MEMORY;
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_samr_nt.c (-33 / +29 lines)
Lines 64-70 Link Here
64
	struct samr_info *info;
64
	struct samr_info *info;
65
	fstring sid_str;
65
	fstring sid_str;
66
66
67
	if ((info = (struct samr_info *)malloc(sizeof(struct samr_info))) == NULL)
67
	if ((info = SMB_MALLOC_P(struct samr_info)) == NULL)
68
		return NULL;
68
		return NULL;
69
69
70
	ZERO_STRUCTP(info);
70
	ZERO_STRUCTP(info);
Lines 175-182 Link Here
175
		if (info->disp_info.num_user_account % MAX_SAM_ENTRIES == 0) {
175
		if (info->disp_info.num_user_account % MAX_SAM_ENTRIES == 0) {
176
		
176
		
177
			DEBUG(10,("load_sampwd_entries: allocating more memory\n"));
177
			DEBUG(10,("load_sampwd_entries: allocating more memory\n"));
178
			pwd_array=(DISP_USER_INFO *)Realloc(info->disp_info.disp_user_info, 
178
			pwd_array= SMB_REALLOC_ARRAY(info->disp_info.disp_user_info, DISP_USER_INFO,
179
			                  (info->disp_info.num_user_account+MAX_SAM_ENTRIES)*sizeof(DISP_USER_INFO));
179
			                  info->disp_info.num_user_account+MAX_SAM_ENTRIES );
180
180
181
			if (pwd_array==NULL)
181
			if (pwd_array==NULL)
182
				return NT_STATUS_NO_MEMORY;
182
				return NT_STATUS_NO_MEMORY;
Lines 214-220 Link Here
214
	static BOOL group_map_init;
214
	static BOOL group_map_init;
215
	extern DOM_SID global_sam_sid;
215
	extern DOM_SID global_sam_sid;
216
216
217
	*ret_map = (GROUP_MAP *)malloc(sizeof(GROUP_MAP)*2);
217
	*ret_map = SMB_MALLOC_ARRAY(GROUP_MAP, 2);
218
	if (!ret_map)
218
	if (!ret_map)
219
		return 2;
219
		return 2;
220
	
220
	
Lines 268-274 Link Here
268
268
269
	info->disp_info.num_group_account=group_entries;
269
	info->disp_info.num_group_account=group_entries;
270
270
271
	grp_array=(DISP_GROUP_INFO *)malloc(info->disp_info.num_group_account*sizeof(DISP_GROUP_INFO));
271
	grp_array=SMB_MALLOC_ARRAY( DISP_GROUP_INFO, info->disp_info.num_group_account );
272
272
273
	if (group_entries!=0 && grp_array==NULL) {
273
	if (group_entries!=0 && grp_array==NULL) {
274
		return NT_STATUS_NO_MEMORY;
274
		return NT_STATUS_NO_MEMORY;
Lines 278-284 Link Here
278
278
279
	for (i=0; i<group_entries; i++) {
279
	for (i=0; i<group_entries; i++) {
280
	
280
	
281
		grp_array[i].grp=(DOMAIN_GRP *)malloc(sizeof(DOMAIN_GRP));
281
		grp_array[i].grp=SMB_MALLOC_P(DOMAIN_GRP);
282
	
282
	
283
		fstrcpy(grp_array[i].grp->name, map[i].nt_name);
283
		fstrcpy(grp_array[i].grp->name, map[i].nt_name);
284
		fstrcpy(grp_array[i].grp->comment, map[i].comment);
284
		fstrcpy(grp_array[i].grp->comment, map[i].comment);
Lines 557-565 Link Here
557
	if (num_sam_entries == 0)
557
	if (num_sam_entries == 0)
558
		return;
558
		return;
559
559
560
	sam = (SAM_ENTRY *)talloc_zero(ctx, sizeof(SAM_ENTRY)*num_sam_entries);
560
	sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_sam_entries);
561
561
562
	uni_name = (UNISTR2 *)talloc_zero(ctx, sizeof(UNISTR2)*num_sam_entries);
562
	uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_sam_entries);
563
563
564
	if (sam == NULL || uni_name == NULL) {
564
	if (sam == NULL || uni_name == NULL) {
565
		DEBUG(0, ("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
565
		DEBUG(0, ("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
Lines 644-652 Link Here
644
	if (num_sam_entries == 0)
644
	if (num_sam_entries == 0)
645
		return;
645
		return;
646
646
647
	sam = (SAM_ENTRY *)talloc_zero(ctx, sizeof(SAM_ENTRY)*num_sam_entries);
647
	sam = TALLOC_ZERO_ARRAY(ctx,SAM_ENTRY, num_sam_entries);
648
648
649
	uni_name = (UNISTR2 *)talloc_zero(ctx, sizeof(UNISTR2)*num_sam_entries);
649
	uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_sam_entries);
650
650
651
	if (sam == NULL || uni_name == NULL) {
651
	if (sam == NULL || uni_name == NULL) {
652
		DEBUG(0, ("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
652
		DEBUG(0, ("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
Lines 982-988 Link Here
982
		DEBUG(5, ("samr_reply_query_dispinfo: buffer size limits to only %d entries\n", max_entries));
982
		DEBUG(5, ("samr_reply_query_dispinfo: buffer size limits to only %d entries\n", max_entries));
983
	}
983
	}
984
984
985
	if (!(ctr = (SAM_DISPINFO_CTR *)talloc_zero(p->mem_ctx,sizeof(SAM_DISPINFO_CTR))))
985
	if (!(ctr = TALLOC_ZERO_P(p->mem_ctx,SAM_DISPINFO_CTR)))
986
		return NT_STATUS_NO_MEMORY;
986
		return NT_STATUS_NO_MEMORY;
987
987
988
	ZERO_STRUCTP(ctr);
988
	ZERO_STRUCTP(ctr);
Lines 991-997 Link Here
991
	switch (q_u->switch_level) {
991
	switch (q_u->switch_level) {
992
	case 0x1:
992
	case 0x1:
993
		if (max_entries) {
993
		if (max_entries) {
994
			if (!(ctr->sam.info1 = (SAM_DISPINFO_1 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_1))))
994
			if (!(ctr->sam.info1 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_1, max_entries)))
995
				return NT_STATUS_NO_MEMORY;
995
				return NT_STATUS_NO_MEMORY;
996
		}
996
		}
997
		disp_ret = init_sam_dispinfo_1(p->mem_ctx, ctr->sam.info1, max_entries, enum_context, info->disp_info.disp_user_info);
997
		disp_ret = init_sam_dispinfo_1(p->mem_ctx, ctr->sam.info1, max_entries, enum_context, info->disp_info.disp_user_info);
Lines 1000-1006 Link Here
1000
		break;
1000
		break;
1001
	case 0x2:
1001
	case 0x2:
1002
		if (max_entries) {
1002
		if (max_entries) {
1003
			if (!(ctr->sam.info2 = (SAM_DISPINFO_2 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_2))))
1003
			if (!(ctr->sam.info2 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_2,max_entries)))
1004
				return NT_STATUS_NO_MEMORY;
1004
				return NT_STATUS_NO_MEMORY;
1005
		}
1005
		}
1006
		disp_ret = init_sam_dispinfo_2(p->mem_ctx, ctr->sam.info2, max_entries, enum_context, info->disp_info.disp_user_info);
1006
		disp_ret = init_sam_dispinfo_2(p->mem_ctx, ctr->sam.info2, max_entries, enum_context, info->disp_info.disp_user_info);
Lines 1009-1015 Link Here
1009
		break;
1009
		break;
1010
	case 0x3:
1010
	case 0x3:
1011
		if (max_entries) {
1011
		if (max_entries) {
1012
			if (!(ctr->sam.info3 = (SAM_DISPINFO_3 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_3))))
1012
			if (!(ctr->sam.info3 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_3,max_entries)))
1013
				return NT_STATUS_NO_MEMORY;
1013
				return NT_STATUS_NO_MEMORY;
1014
		}
1014
		}
1015
		disp_ret = init_sam_dispinfo_3(p->mem_ctx, ctr->sam.info3, max_entries, enum_context, info->disp_info.disp_group_info);
1015
		disp_ret = init_sam_dispinfo_3(p->mem_ctx, ctr->sam.info3, max_entries, enum_context, info->disp_info.disp_group_info);
Lines 1018-1024 Link Here
1018
		break;
1018
		break;
1019
	case 0x4:
1019
	case 0x4:
1020
		if (max_entries) {
1020
		if (max_entries) {
1021
			if (!(ctr->sam.info4 = (SAM_DISPINFO_4 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_4))))
1021
			if (!(ctr->sam.info4 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_4,max_entries)))
1022
				return NT_STATUS_NO_MEMORY;
1022
				return NT_STATUS_NO_MEMORY;
1023
		}
1023
		}
1024
		disp_ret = init_sam_dispinfo_4(p->mem_ctx, ctr->sam.info4, max_entries, enum_context, info->disp_info.disp_user_info);
1024
		disp_ret = init_sam_dispinfo_4(p->mem_ctx, ctr->sam.info4, max_entries, enum_context, info->disp_info.disp_user_info);
Lines 1027-1033 Link Here
1027
		break;
1027
		break;
1028
	case 0x5:
1028
	case 0x5:
1029
		if (max_entries) {
1029
		if (max_entries) {
1030
			if (!(ctr->sam.info5 = (SAM_DISPINFO_5 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_5))))
1030
			if (!(ctr->sam.info5 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_5,max_entries)))
1031
				return NT_STATUS_NO_MEMORY;
1031
				return NT_STATUS_NO_MEMORY;
1032
		}
1032
		}
1033
		disp_ret = init_sam_dispinfo_5(p->mem_ctx, ctr->sam.info5, max_entries, enum_context, info->disp_info.disp_group_info);
1033
		disp_ret = init_sam_dispinfo_5(p->mem_ctx, ctr->sam.info5, max_entries, enum_context, info->disp_info.disp_group_info);
Lines 1287-1297 Link Here
1287
	*pp_hdr_name = NULL;
1287
	*pp_hdr_name = NULL;
1288
1288
1289
	if (num_names != 0) {
1289
	if (num_names != 0) {
1290
		hdr_name = (UNIHDR *)talloc_zero(ctx, sizeof(UNIHDR)*num_names);
1290
		hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR,num_names);
1291
		if (hdr_name == NULL)
1291
		if (hdr_name == NULL)
1292
			return False;
1292
			return False;
1293
1293
1294
		uni_name = (UNISTR2 *)talloc_zero(ctx,sizeof(UNISTR2)*num_names);
1294
		uni_name = TALLOC_ZERO_ARRAY(ctx,UNISTR2,num_names);
1295
		if (uni_name == NULL)
1295
		if (uni_name == NULL)
1296
			return False;
1296
			return False;
1297
	}
1297
	}
Lines 1337-1343 Link Here
1337
	}
1337
	}
1338
1338
1339
	if (num_rids) {
1339
	if (num_rids) {
1340
		if ((group_attrs = (uint32 *)talloc_zero(p->mem_ctx, num_rids * sizeof(uint32))) == NULL)
1340
		if ((group_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids)) == NULL)
1341
			return NT_STATUS_NO_MEMORY;
1341
			return NT_STATUS_NO_MEMORY;
1342
	}
1342
	}
1343
1343
Lines 1610-1616 Link Here
1610
1610
1611
	DEBUG(5,("_samr_query_userinfo: rid:0x%x\n", rid));
1611
	DEBUG(5,("_samr_query_userinfo: rid:0x%x\n", rid));
1612
1612
1613
	ctr = (SAM_USERINFO_CTR *)talloc_zero(p->mem_ctx, sizeof(SAM_USERINFO_CTR));
1613
	ctr = TALLOC_ZERO_P(p->mem_ctx,SAM_USERINFO_CTR);
1614
	if (!ctr)
1614
	if (!ctr)
1615
		return NT_STATUS_NO_MEMORY;
1615
		return NT_STATUS_NO_MEMORY;
1616
1616
Lines 1621-1627 Link Here
1621
1621
1622
	switch (q_u->switch_value) {
1622
	switch (q_u->switch_value) {
1623
	case 0x10:
1623
	case 0x10:
1624
		ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(p->mem_ctx, sizeof(SAM_USER_INFO_10));
1624
		ctr->info.id10 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_10);
1625
		if (ctr->info.id10 == NULL)
1625
		if (ctr->info.id10 == NULL)
1626
			return NT_STATUS_NO_MEMORY;
1626
			return NT_STATUS_NO_MEMORY;
1627
1627
Lines 1639-1649 Link Here
1639
            expire.low = 0xffffffff;
1639
            expire.low = 0xffffffff;
1640
            expire.high = 0x7fffffff;
1640
            expire.high = 0x7fffffff;
1641
1641
1642
            ctr->info.id = (SAM_USER_INFO_11 *)talloc_zero(p->mem_ctx,
1642
            ctr->info.id = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_11);
1643
                                    sizeof
1644
                                    (*ctr->
1645
                                     info.
1646
                                     id11));
1647
            init_sam_user_info11(ctr->info.id11, &expire,
1643
            init_sam_user_info11(ctr->info.id11, &expire,
1648
                         "BROOKFIELDS$",    /* name */
1644
                         "BROOKFIELDS$",    /* name */
1649
                         0x03ef,    /* user rid */
1645
                         0x03ef,    /* user rid */
Lines 1655-1661 Link Here
1655
#endif
1651
#endif
1656
1652
1657
	case 0x12:
1653
	case 0x12:
1658
		ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(p->mem_ctx, sizeof(SAM_USER_INFO_12));
1654
		ctr->info.id12 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_12);
1659
		if (ctr->info.id12 == NULL)
1655
		if (ctr->info.id12 == NULL)
1660
			return NT_STATUS_NO_MEMORY;
1656
			return NT_STATUS_NO_MEMORY;
1661
1657
Lines 1664-1670 Link Here
1664
		break;
1660
		break;
1665
1661
1666
	case 20:
1662
	case 20:
1667
		ctr->info.id20 = (SAM_USER_INFO_20 *)talloc_zero(p->mem_ctx,sizeof(SAM_USER_INFO_20));
1663
		ctr->info.id20 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_20);
1668
		if (ctr->info.id20 == NULL)
1664
		if (ctr->info.id20 == NULL)
1669
			return NT_STATUS_NO_MEMORY;
1665
			return NT_STATUS_NO_MEMORY;
1670
		if (!get_user_info_20(ctr->info.id20, rid))
1666
		if (!get_user_info_20(ctr->info.id20, rid))
Lines 1672-1678 Link Here
1672
		break;
1668
		break;
1673
1669
1674
	case 21:
1670
	case 21:
1675
		ctr->info.id21 = (SAM_USER_INFO_21 *)talloc_zero(p->mem_ctx,sizeof(SAM_USER_INFO_21));
1671
		ctr->info.id21 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_21);
1676
		if (ctr->info.id21 == NULL)
1672
		if (ctr->info.id21 == NULL)
1677
			return NT_STATUS_NO_MEMORY;
1673
			return NT_STATUS_NO_MEMORY;
1678
		if (!get_user_info_21(ctr->info.id21, rid))
1674
		if (!get_user_info_21(ctr->info.id21, rid))
Lines 1764-1770 Link Here
1764
1760
1765
	uint32 num_users=0, num_groups=0, num_aliases=0;
1761
	uint32 num_users=0, num_groups=0, num_aliases=0;
1766
1762
1767
	if ((ctr = (SAM_UNK_CTR *)talloc_zero(p->mem_ctx, sizeof(SAM_UNK_CTR))) == NULL)
1763
	if ((ctr = TALLOC_ZERO_P(p->mem_ctx,SAM_UNK_CTR)) == NULL)
1768
		return NT_STATUS_NO_MEMORY;
1764
		return NT_STATUS_NO_MEMORY;
1769
1765
1770
	ZERO_STRUCTP(ctr);
1766
	ZERO_STRUCTP(ctr);
Lines 2073-2080 Link Here
2073
	if (num_sam_entries == 0)
2069
	if (num_sam_entries == 0)
2074
		return True;
2070
		return True;
2075
2071
2076
	sam = (SAM_ENTRY *)talloc_zero(ctx, sizeof(SAM_ENTRY)*num_sam_entries);
2072
	sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_sam_entries);
2077
	uni_name = (UNISTR2 *)talloc_zero(ctx, sizeof(UNISTR2)*num_sam_entries);
2073
	uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_sam_entries);
2078
2074
2079
	if (sam == NULL || uni_name == NULL)
2075
	if (sam == NULL || uni_name == NULL)
2080
		return False;
2076
		return False;
Lines 2603-2609 Link Here
2603
	int num_rids;
2599
	int num_rids;
2604
2600
2605
	num_rids = 1;
2601
	num_rids = 1;
2606
	rid=(uint32 *)talloc_zero(p->mem_ctx, num_rids*sizeof(uint32));
2602
	rid=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids);
2607
	if (rid == NULL)
2603
	if (rid == NULL)
2608
		return NT_STATUS_NO_MEMORY;
2604
		return NT_STATUS_NO_MEMORY;
2609
2605
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_spoolss_nt.c (-75 / +75 lines)
Lines 233-239 Link Here
233
	if (!sp)
233
	if (!sp)
234
		return NULL;
234
		return NULL;
235
235
236
	new_sp = (SPOOL_NOTIFY_OPTION *)malloc(sizeof(SPOOL_NOTIFY_OPTION));
236
	new_sp = SMB_MALLOC_P(SPOOL_NOTIFY_OPTION);
237
	if (!new_sp)
237
	if (!new_sp)
238
		return NULL;
238
		return NULL;
239
239
Lines 494-500 Link Here
494
494
495
	DEBUG(10,("open_printer_hnd: name [%s]\n", name));
495
	DEBUG(10,("open_printer_hnd: name [%s]\n", name));
496
496
497
	if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
497
	if((new_printer=SMB_MALLOC_P(Printer_entry)) == NULL)
498
		return False;
498
		return False;
499
499
500
	ZERO_STRUCTP(new_printer);
500
	ZERO_STRUCTP(new_printer);
Lines 872-878 Link Here
872
	
872
	
873
	/* bulk copy first */
873
	/* bulk copy first */
874
	
874
	
875
	d = talloc_memdup(ctx, devmode, sizeof(DEVICEMODE));
875
	d = TALLOC_MEMDUP(ctx, devmode, sizeof(DEVICEMODE));
876
	if (!d)
876
	if (!d)
877
		return NULL;
877
		return NULL;
878
		
878
		
Lines 880-886 Link Here
880
	
880
	
881
	len = unistrlen(devmode->devicename.buffer);
881
	len = unistrlen(devmode->devicename.buffer);
882
	if (len != -1) {
882
	if (len != -1) {
883
		d->devicename.buffer = talloc(ctx, len*2);
883
		d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len);
884
		if (unistrcpy(d->devicename.buffer, devmode->devicename.buffer) != len)
884
		if (unistrcpy(d->devicename.buffer, devmode->devicename.buffer) != len)
885
			return NULL;
885
			return NULL;
886
	}
886
	}
Lines 888-899 Link Here
888
888
889
	len = unistrlen(devmode->formname.buffer);
889
	len = unistrlen(devmode->formname.buffer);
890
	if (len != -1) {
890
	if (len != -1) {
891
		d->devicename.buffer = talloc(ctx, len*2);
891
		d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len);
892
		if (unistrcpy(d->formname.buffer, devmode->formname.buffer) != len)
892
		if (unistrcpy(d->formname.buffer, devmode->formname.buffer) != len)
893
			return NULL;
893
			return NULL;
894
	}
894
	}
895
895
896
	d->private = talloc_memdup(ctx, devmode->private, devmode->driverextra);
896
	d->private = TALLOC_MEMDUP(ctx, devmode->private, devmode->driverextra);
897
	
897
	
898
	return d;
898
	return d;
899
}
899
}
Lines 1305-1311 Link Here
1305
	if ((devmode->driverextra != 0) && (devmode->private != NULL)) {
1305
	if ((devmode->driverextra != 0) && (devmode->private != NULL)) {
1306
		SAFE_FREE(nt_devmode->private);
1306
		SAFE_FREE(nt_devmode->private);
1307
		nt_devmode->driverextra=devmode->driverextra;
1307
		nt_devmode->driverextra=devmode->driverextra;
1308
		if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL)
1308
		if((nt_devmode->private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL)
1309
			return False;
1309
			return False;
1310
		memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra);
1310
		memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra);
1311
	}
1311
	}
Lines 1521-1527 Link Here
1521
		
1521
		
1522
	if (!strcmp(value, "W3SvcInstalled")) {
1522
	if (!strcmp(value, "W3SvcInstalled")) {
1523
		*type = 0x4;
1523
		*type = 0x4;
1524
		if((*data = (uint8 *)talloc_zero(ctx, 4*sizeof(uint8) )) == NULL)
1524
		if((*data = (uint8 *)TALLOC_ZERO(ctx, 4*sizeof(uint8) )) == NULL)
1525
			return False;
1525
			return False;
1526
		*needed = 0x4;			
1526
		*needed = 0x4;			
1527
		return True;
1527
		return True;
Lines 1529-1535 Link Here
1529
1529
1530
	if (!strcmp(value, "BeepEnabled")) {
1530
	if (!strcmp(value, "BeepEnabled")) {
1531
		*type = 0x4;
1531
		*type = 0x4;
1532
		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
1532
		if((*data = (uint8 *)TALLOC(ctx, 4*sizeof(uint8) )) == NULL)
1533
			return False;
1533
			return False;
1534
		SIVAL(*data, 0, 0x00);
1534
		SIVAL(*data, 0, 0x00);
1535
		*needed = 0x4;			
1535
		*needed = 0x4;			
Lines 1538-1544 Link Here
1538
1538
1539
	if (!strcmp(value, "EventLog")) {
1539
	if (!strcmp(value, "EventLog")) {
1540
		*type = 0x4;
1540
		*type = 0x4;
1541
		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
1541
		if((*data = (uint8 *)TALLOC(ctx, 4*sizeof(uint8) )) == NULL)
1542
			return False;
1542
			return False;
1543
		/* formally was 0x1b */
1543
		/* formally was 0x1b */
1544
		SIVAL(*data, 0, 0x0);
1544
		SIVAL(*data, 0, 0x0);
Lines 1548-1554 Link Here
1548
1548
1549
	if (!strcmp(value, "NetPopup")) {
1549
	if (!strcmp(value, "NetPopup")) {
1550
		*type = 0x4;
1550
		*type = 0x4;
1551
		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
1551
		if((*data = (uint8 *)TALLOC(ctx, 4*sizeof(uint8) )) == NULL)
1552
			return False;
1552
			return False;
1553
		SIVAL(*data, 0, 0x00);
1553
		SIVAL(*data, 0, 0x00);
1554
		*needed = 0x4;
1554
		*needed = 0x4;
Lines 1557-1563 Link Here
1557
1557
1558
	if (!strcmp(value, "MajorVersion")) {
1558
	if (!strcmp(value, "MajorVersion")) {
1559
		*type = 0x4;
1559
		*type = 0x4;
1560
		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
1560
		if((*data = (uint8 *)TALLOC(ctx, 4*sizeof(uint8) )) == NULL)
1561
			return False;
1561
			return False;
1562
#ifndef EMULATE_WIN2K_HACK /* JERRY */
1562
#ifndef EMULATE_WIN2K_HACK /* JERRY */
1563
		SIVAL(*data, 0, 2);
1563
		SIVAL(*data, 0, 2);
Lines 1574-1580 Link Here
1574
		fstrcpy(string, string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
1574
		fstrcpy(string, string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
1575
		*type = 0x1;			
1575
		*type = 0x1;			
1576
		*needed = 2*(strlen(string)+1);		
1576
		*needed = 2*(strlen(string)+1);		
1577
		if((*data  = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
1577
		if((*data  = (uint8 *)TALLOC(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
1578
			return False;
1578
			return False;
1579
		memset(*data, 0, (*needed > in_size) ? *needed:in_size);
1579
		memset(*data, 0, (*needed > in_size) ? *needed:in_size);
1580
		
1580
		
Lines 1590-1596 Link Here
1590
		pstring string="Windows NT x86";
1590
		pstring string="Windows NT x86";
1591
		*type = 0x1;			
1591
		*type = 0x1;			
1592
		*needed = 2*(strlen(string)+1);	
1592
		*needed = 2*(strlen(string)+1);	
1593
		if((*data  = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
1593
		if((*data  = (uint8 *)TALLOC(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
1594
			return False;
1594
			return False;
1595
		memset(*data, 0, (*needed > in_size) ? *needed:in_size);
1595
		memset(*data, 0, (*needed > in_size) ? *needed:in_size);
1596
		for (i=0; i<strlen(string); i++) {
1596
		for (i=0; i<strlen(string); i++) {
Lines 1640-1646 Link Here
1640
	DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size));
1640
	DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size));
1641
1641
1642
	if (in_size) {
1642
	if (in_size) {
1643
		if((*data  = (uint8 *)talloc(ctx, in_size *sizeof(uint8) )) == NULL) {
1643
		if((*data  = TALLOC_ARRAY(ctx, uint8, in_size )) == NULL) {
1644
			return False;
1644
			return False;
1645
		}
1645
		}
1646
1646
Lines 1694-1700 Link Here
1694
	DEBUG(4,("_spoolss_getprinterdata\n"));
1694
	DEBUG(4,("_spoolss_getprinterdata\n"));
1695
	
1695
	
1696
	if (!Printer) {
1696
	if (!Printer) {
1697
		if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL)
1697
		if((*data=TALLOC_ZERO_ARRAY(p->mem_ctx, uint8, 4)) == NULL)
1698
			return WERR_NOMEM;
1698
			return WERR_NOMEM;
1699
		DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
1699
		DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
1700
		return WERR_BADFID;
1700
		return WERR_BADFID;
Lines 1711-1717 Link Here
1711
		DEBUG(5, ("value not found, allocating %d\n", *out_size));
1711
		DEBUG(5, ("value not found, allocating %d\n", *out_size));
1712
		/* reply this param doesn't exist */
1712
		/* reply this param doesn't exist */
1713
		if (*out_size) {
1713
		if (*out_size) {
1714
			if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL)
1714
			if((*data=TALLOC_ZERO_ARRAY(p->mem_ctx, uint8, *out_size)) == NULL)
1715
				return WERR_NOMEM;
1715
				return WERR_NOMEM;
1716
		} else {
1716
		} else {
1717
			*data = NULL;
1717
			*data = NULL;
Lines 1837-1843 Link Here
1837
	len = (uint32)dos_PutUniCode(temp, temp_name, sizeof(temp) - 2, True);
1837
	len = (uint32)dos_PutUniCode(temp, temp_name, sizeof(temp) - 2, True);
1838
1838
1839
	data->notify_data.data.length = len / 2 - 1;
1839
	data->notify_data.data.length = len / 2 - 1;
1840
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
1840
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
1841
1841
1842
	if (!data->notify_data.data.string) {
1842
	if (!data->notify_data.data.string) {
1843
		data->notify_data.data.length = 0;
1843
		data->notify_data.data.length = 0;
Lines 1872-1878 Link Here
1872
	len = (uint32)dos_PutUniCode(temp, p, sizeof(temp) - 2, True);
1872
	len = (uint32)dos_PutUniCode(temp, p, sizeof(temp) - 2, True);
1873
1873
1874
	data->notify_data.data.length = len / 2 - 1;
1874
	data->notify_data.data.length = len / 2 - 1;
1875
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
1875
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
1876
	
1876
	
1877
	if (!data->notify_data.data.string) {
1877
	if (!data->notify_data.data.string) {
1878
		data->notify_data.data.length = 0;
1878
		data->notify_data.data.length = 0;
Lines 1899-1905 Link Here
1899
				     sizeof(temp) - 2, True);
1899
				     sizeof(temp) - 2, True);
1900
1900
1901
	data->notify_data.data.length = len / 2 - 1;
1901
	data->notify_data.data.length = len / 2 - 1;
1902
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
1902
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
1903
	
1903
	
1904
	if (!data->notify_data.data.string) {
1904
	if (!data->notify_data.data.string) {
1905
		data->notify_data.data.length = 0;
1905
		data->notify_data.data.length = 0;
Lines 1928-1934 Link Here
1928
				     sizeof(temp) - 2, True);
1928
				     sizeof(temp) - 2, True);
1929
1929
1930
	data->notify_data.data.length = len / 2 - 1;
1930
	data->notify_data.data.length = len / 2 - 1;
1931
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
1931
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
1932
	
1932
	
1933
	if (!data->notify_data.data.string) {
1933
	if (!data->notify_data.data.string) {
1934
		data->notify_data.data.length = 0;
1934
		data->notify_data.data.length = 0;
Lines 1956-1962 Link Here
1956
				     sizeof(temp) - 2, True);
1956
				     sizeof(temp) - 2, True);
1957
1957
1958
	data->notify_data.data.length = len / 2 - 1;
1958
	data->notify_data.data.length = len / 2 - 1;
1959
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
1959
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
1960
	
1960
	
1961
	if (!data->notify_data.data.string) {
1961
	if (!data->notify_data.data.string) {
1962
		data->notify_data.data.length = 0;
1962
		data->notify_data.data.length = 0;
Lines 1987-1993 Link Here
1987
					     sizeof(temp) - 2, True);
1987
					     sizeof(temp) - 2, True);
1988
1988
1989
	data->notify_data.data.length = len / 2 - 1;
1989
	data->notify_data.data.length = len / 2 - 1;
1990
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
1990
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
1991
	
1991
	
1992
	if (!data->notify_data.data.string) {
1992
	if (!data->notify_data.data.string) {
1993
		data->notify_data.data.length = 0;
1993
		data->notify_data.data.length = 0;
Lines 2015-2021 Link Here
2015
				     sizeof(temp) - 2, True);
2015
				     sizeof(temp) - 2, True);
2016
2016
2017
	data->notify_data.data.length = len / 2 - 1;
2017
	data->notify_data.data.length = len / 2 - 1;
2018
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
2018
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2019
	
2019
	
2020
	if (!data->notify_data.data.string) {
2020
	if (!data->notify_data.data.string) {
2021
		data->notify_data.data.length = 0;
2021
		data->notify_data.data.length = 0;
Lines 2055-2061 Link Here
2055
				     sizeof(temp) - 2, True);
2055
				     sizeof(temp) - 2, True);
2056
2056
2057
	data->notify_data.data.length = len / 2 - 1;
2057
	data->notify_data.data.length = len / 2 - 1;
2058
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
2058
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2059
	
2059
	
2060
	if (!data->notify_data.data.string) {
2060
	if (!data->notify_data.data.string) {
2061
		data->notify_data.data.length = 0;
2061
		data->notify_data.data.length = 0;
Lines 2083-2089 Link Here
2083
				     sizeof(temp) - 2, True);
2083
				     sizeof(temp) - 2, True);
2084
2084
2085
	data->notify_data.data.length = len / 2 - 1;
2085
	data->notify_data.data.length = len / 2 - 1;
2086
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
2086
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2087
	
2087
	
2088
	if (!data->notify_data.data.string) {
2088
	if (!data->notify_data.data.string) {
2089
		data->notify_data.data.length = 0;
2089
		data->notify_data.data.length = 0;
Lines 2111-2117 Link Here
2111
				     sizeof(temp) - 2, True);
2111
				     sizeof(temp) - 2, True);
2112
2112
2113
	data->notify_data.data.length = len / 2 - 1;
2113
	data->notify_data.data.length = len / 2 - 1;
2114
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
2114
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2115
	
2115
	
2116
	if (!data->notify_data.data.string) {
2116
	if (!data->notify_data.data.string) {
2117
		data->notify_data.data.length = 0;
2117
		data->notify_data.data.length = 0;
Lines 2139-2145 Link Here
2139
				     sizeof(pstring) - 2, True);
2139
				     sizeof(pstring) - 2, True);
2140
2140
2141
	data->notify_data.data.length = len / 2 - 1;
2141
	data->notify_data.data.length = len / 2 - 1;
2142
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
2142
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2143
	
2143
	
2144
	if (!data->notify_data.data.string) {
2144
	if (!data->notify_data.data.string) {
2145
		data->notify_data.data.length = 0;
2145
		data->notify_data.data.length = 0;
Lines 2300-2306 Link Here
2300
				     sizeof(temp) - 2, True);
2300
				     sizeof(temp) - 2, True);
2301
2301
2302
	data->notify_data.data.length = len / 2 - 1;
2302
	data->notify_data.data.length = len / 2 - 1;
2303
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
2303
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2304
	
2304
	
2305
	if (!data->notify_data.data.string) {
2305
	if (!data->notify_data.data.string) {
2306
		data->notify_data.data.length = 0;
2306
		data->notify_data.data.length = 0;
Lines 2341-2347 Link Here
2341
				     True);
2341
				     True);
2342
2342
2343
	data->notify_data.data.length = len / 2 - 1;
2343
	data->notify_data.data.length = len / 2 - 1;
2344
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
2344
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2345
	
2345
	
2346
	if (!data->notify_data.data.string) {
2346
	if (!data->notify_data.data.string) {
2347
		data->notify_data.data.length = 0;
2347
		data->notify_data.data.length = 0;
Lines 2391-2397 Link Here
2391
	len = (uint32)dos_PutUniCode(temp, p, sizeof(temp) - 2, True);
2391
	len = (uint32)dos_PutUniCode(temp, p, sizeof(temp) - 2, True);
2392
2392
2393
	data->notify_data.data.length = len / 2 - 1;
2393
	data->notify_data.data.length = len / 2 - 1;
2394
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
2394
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2395
	
2395
	
2396
	if (!data->notify_data.data.string) {
2396
	if (!data->notify_data.data.string) {
2397
		data->notify_data.data.length = 0;
2397
		data->notify_data.data.length = 0;
Lines 2489-2495 Link Here
2489
	len = sizeof(SYSTEMTIME);
2489
	len = sizeof(SYSTEMTIME);
2490
2490
2491
	data->notify_data.data.length = len;
2491
	data->notify_data.data.length = len;
2492
	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
2492
	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2493
2493
2494
	if (!data->notify_data.data.string) {
2494
	if (!data->notify_data.data.string) {
2495
		data->notify_data.data.length = 0;
2495
		data->notify_data.data.length = 0;
Lines 2704-2710 Link Here
2704
		if (!search_notify(type, field, &j) )
2704
		if (!search_notify(type, field, &j) )
2705
			continue;
2705
			continue;
2706
2706
2707
		if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
2707
		if((tid=SMB_REALLOC_ARRAY( info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1 )) == NULL) {
2708
			DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
2708
			DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
2709
			return False;
2709
			return False;
2710
		}
2710
		}
Lines 2760-2766 Link Here
2760
		if (!search_notify(type, field, &j) )
2760
		if (!search_notify(type, field, &j) )
2761
			continue;
2761
			continue;
2762
2762
2763
		if((tid=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
2763
		if((tid=SMB_REALLOC_ARRAY( info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1 )) == NULL) {
2764
			DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
2764
			DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
2765
			return False;
2765
			return False;
2766
		}
2766
		}
Lines 3040-3046 Link Here
3040
3040
3041
	/* it's the first time, add it to the list */
3041
	/* it's the first time, add it to the list */
3042
	if (session_counter==NULL) {
3042
	if (session_counter==NULL) {
3043
		if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL) {
3043
		if((session_counter=SMB_MALLOC_P(counter_printer_0)) == NULL) {
3044
			free_a_printer(&ntprinter, 2);
3044
			free_a_printer(&ntprinter, 2);
3045
			return False;
3045
			return False;
3046
		}
3046
		}
Lines 3184-3190 Link Here
3184
	
3184
	
3185
	DEBUGADD(8,("getting printer characteristics\n"));
3185
	DEBUGADD(8,("getting printer characteristics\n"));
3186
3186
3187
	if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) {
3187
	if ((devmode = SMB_MALLOC_P(DEVICEMODE)) == NULL) {
3188
		DEBUG(2,("construct_dev_mode: malloc fail.\n"));
3188
		DEBUG(2,("construct_dev_mode: malloc fail.\n"));
3189
		return NULL;
3189
		return NULL;
3190
	}
3190
	}
Lines 3330-3336 Link Here
3330
		return False;
3330
		return False;
3331
3331
3332
	*pp_printer = NULL;
3332
	*pp_printer = NULL;
3333
	if ((printer = (PRINTER_INFO_3 *)malloc(sizeof(PRINTER_INFO_3))) == NULL) {
3333
	if ((printer = SMB_MALLOC_P(PRINTER_INFO_3)) == NULL) {
3334
		DEBUG(2,("construct_printer_info_3: malloc fail.\n"));
3334
		DEBUG(2,("construct_printer_info_3: malloc fail.\n"));
3335
		return False;
3335
		return False;
3336
	}
3336
	}
Lines 3432-3438 Link Here
3432
			DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
3432
			DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
3433
3433
3434
			if (construct_printer_info_1(flags, &current_prt, snum)) {
3434
			if (construct_printer_info_1(flags, &current_prt, snum)) {
3435
				if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) {
3435
				if((tp=SMB_REALLOC_ARRAY( printers, PRINTER_INFO_1, *returned +1 )) == NULL) {
3436
					DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n"));
3436
					DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n"));
3437
					SAFE_FREE(printers);
3437
					SAFE_FREE(printers);
3438
					*returned=0;
3438
					*returned=0;
Lines 3519-3525 Link Here
3519
	 * We should have a TDB here. The registration is done thru an undocumented RPC call.
3519
	 * We should have a TDB here. The registration is done thru an undocumented RPC call.
3520
	 */
3520
	 */
3521
	
3521
	
3522
	if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL)
3522
	if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
3523
		return WERR_NOMEM;
3523
		return WERR_NOMEM;
3524
3524
3525
	*returned=1;
3525
	*returned=1;
Lines 3601-3607 Link Here
3601
			DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
3601
			DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
3602
				
3602
				
3603
			if (construct_printer_info_2(&current_prt, snum)) {
3603
			if (construct_printer_info_2(&current_prt, snum)) {
3604
				if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) {
3604
				if((tp=SMB_REALLOC_ARRAY( printers, PRINTER_INFO_2, *returned +1 )) == NULL) {
3605
					DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n"));
3605
					DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n"));
3606
					SAFE_FREE(printers);
3606
					SAFE_FREE(printers);
3607
					*returned = 0;
3607
					*returned = 0;
Lines 3775-3781 Link Here
3775
{
3775
{
3776
	PRINTER_INFO_0 *printer=NULL;
3776
	PRINTER_INFO_0 *printer=NULL;
3777
3777
3778
	if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL)
3778
	if((printer=SMB_MALLOC_P(PRINTER_INFO_0)) == NULL)
3779
		return WERR_NOMEM;
3779
		return WERR_NOMEM;
3780
3780
3781
	construct_printer_info_0(printer, snum);
3781
	construct_printer_info_0(printer, snum);
Lines 3808-3814 Link Here
3808
{
3808
{
3809
	PRINTER_INFO_1 *printer=NULL;
3809
	PRINTER_INFO_1 *printer=NULL;
3810
3810
3811
	if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL)
3811
	if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
3812
		return WERR_NOMEM;
3812
		return WERR_NOMEM;
3813
3813
3814
	construct_printer_info_1(PRINTER_ENUM_ICON8, printer, snum);
3814
	construct_printer_info_1(PRINTER_ENUM_ICON8, printer, snum);
Lines 3841-3847 Link Here
3841
{
3841
{
3842
	PRINTER_INFO_2 *printer=NULL;
3842
	PRINTER_INFO_2 *printer=NULL;
3843
3843
3844
	if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL)
3844
	if((printer=SMB_MALLOC_P(PRINTER_INFO_2))==NULL)
3845
		return WERR_NOMEM;
3845
		return WERR_NOMEM;
3846
	
3846
	
3847
	construct_printer_info_2(printer, snum);
3847
	construct_printer_info_2(printer, snum);
Lines 3908-3914 Link Here
3908
{
3908
{
3909
	PRINTER_INFO_4 *printer=NULL;
3909
	PRINTER_INFO_4 *printer=NULL;
3910
3910
3911
	if((printer=(PRINTER_INFO_4*)malloc(sizeof(PRINTER_INFO_4)))==NULL)
3911
	if((printer=SMB_MALLOC_P(PRINTER_INFO_4))==NULL)
3912
		return WERR_NOMEM;
3912
		return WERR_NOMEM;
3913
3913
3914
	if (!construct_printer_info_4(printer, snum))
3914
	if (!construct_printer_info_4(printer, snum))
Lines 3942-3948 Link Here
3942
{
3942
{
3943
	PRINTER_INFO_5 *printer=NULL;
3943
	PRINTER_INFO_5 *printer=NULL;
3944
3944
3945
	if((printer=(PRINTER_INFO_5*)malloc(sizeof(PRINTER_INFO_5)))==NULL)
3945
	if((printer=SMB_MALLOC_P(PRINTER_INFO_5))==NULL)
3946
		return WERR_NOMEM;
3946
		return WERR_NOMEM;
3947
3947
3948
	if (!construct_printer_info_5(printer, snum))
3948
	if (!construct_printer_info_5(printer, snum))
Lines 4128-4134 Link Here
4128
		if (strlen(v) == 0) break;
4128
		if (strlen(v) == 0) break;
4129
		slprintf(line, sizeof(line)-1, "\\\\%s%s", servername, v);
4129
		slprintf(line, sizeof(line)-1, "\\\\%s%s", servername, v);
4130
		DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line)));
4130
		DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line)));
4131
		if((tuary=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) {
4131
		if((tuary= SMB_REALLOC_ARRAY( *uni_array, uint16, j+strlen(line)+2 )) == NULL) {
4132
			DEBUG(2,("init_unistr_array: Realloc error\n" ));
4132
			DEBUG(2,("init_unistr_array: Realloc error\n" ));
4133
			return;
4133
			return;
4134
		} else
4134
		} else
Lines 4385-4391 Link Here
4385
	DRIVER_INFO_1 *info=NULL;
4385
	DRIVER_INFO_1 *info=NULL;
4386
	WERROR status;
4386
	WERROR status;
4387
	
4387
	
4388
	if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL)
4388
	if((info=SMB_MALLOC_P(DRIVER_INFO_1)) == NULL)
4389
		return WERR_NOMEM;
4389
		return WERR_NOMEM;
4390
	
4390
	
4391
	status=construct_printer_driver_info_1(info, snum, servername, architecture, version);
4391
	status=construct_printer_driver_info_1(info, snum, servername, architecture, version);
Lines 4422-4428 Link Here
4422
	DRIVER_INFO_2 *info=NULL;
4422
	DRIVER_INFO_2 *info=NULL;
4423
	WERROR status;
4423
	WERROR status;
4424
	
4424
	
4425
	if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL)
4425
	if((info=SMB_MALLOC_P(DRIVER_INFO_2)) == NULL)
4426
		return WERR_NOMEM;
4426
		return WERR_NOMEM;
4427
	
4427
	
4428
	status=construct_printer_driver_info_2(info, snum, servername, architecture, version);
4428
	status=construct_printer_driver_info_2(info, snum, servername, architecture, version);
Lines 5541-5547 Link Here
5541
	JOB_INFO_1 *info;
5541
	JOB_INFO_1 *info;
5542
	int i;
5542
	int i;
5543
	
5543
	
5544
	info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1));
5544
	info=SMB_MALLOC_ARRAY(JOB_INFO_1, *returned);
5545
	if (info==NULL) {
5545
	if (info==NULL) {
5546
		SAFE_FREE(queue);
5546
		SAFE_FREE(queue);
5547
		*returned=0;
5547
		*returned=0;
Lines 5591-5597 Link Here
5591
	WERROR result;
5591
	WERROR result;
5592
	DEVICEMODE *devmode = NULL;
5592
	DEVICEMODE *devmode = NULL;
5593
	
5593
	
5594
	info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2));
5594
	info=SMB_MALLOC_ARRAY(JOB_INFO_2, *returned );
5595
	if (info==NULL) {
5595
	if (info==NULL) {
5596
		*returned=0;
5596
		*returned=0;
5597
		result = WERR_NOMEM;
5597
		result = WERR_NOMEM;
Lines 5783-5789 Link Here
5783
			return WERR_NOMEM;
5783
			return WERR_NOMEM;
5784
5784
5785
		if(ndrivers != 0) {
5785
		if(ndrivers != 0) {
5786
			if((tdi1=(DRIVER_INFO_1 *)Realloc(driver_info_1, (*returned+ndrivers) * sizeof(DRIVER_INFO_1))) == NULL) {
5786
			if((tdi1=SMB_REALLOC_ARRAY(driver_info_1, DRIVER_INFO_1, *returned+ndrivers )) == NULL) {
5787
				DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n"));
5787
				DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n"));
5788
				SAFE_FREE(driver_info_1);
5788
				SAFE_FREE(driver_info_1);
5789
				SAFE_FREE(list);
5789
				SAFE_FREE(list);
Lines 5864-5870 Link Here
5864
			return WERR_NOMEM;
5864
			return WERR_NOMEM;
5865
5865
5866
		if(ndrivers != 0) {
5866
		if(ndrivers != 0) {
5867
			if((tdi2=(DRIVER_INFO_2 *)Realloc(driver_info_2, (*returned+ndrivers) * sizeof(DRIVER_INFO_2))) == NULL) {
5867
			if((tdi2= SMB_REALLOC_ARRAY( driver_info_2, DRIVER_INFO_2, *returned+ndrivers )) == NULL) {
5868
				DEBUG(0,("enumprinterdrivers_level2: failed to enlarge driver info buffer!\n"));
5868
				DEBUG(0,("enumprinterdrivers_level2: failed to enlarge driver info buffer!\n"));
5869
				SAFE_FREE(driver_info_2);
5869
				SAFE_FREE(driver_info_2);
5870
				SAFE_FREE(list);
5870
				SAFE_FREE(list);
Lines 5946-5952 Link Here
5946
			return WERR_NOMEM;
5946
			return WERR_NOMEM;
5947
5947
5948
		if(ndrivers != 0) {
5948
		if(ndrivers != 0) {
5949
			if((tdi3=(DRIVER_INFO_3 *)Realloc(driver_info_3, (*returned+ndrivers) * sizeof(DRIVER_INFO_3))) == NULL) {
5949
			if((tdi3=SMB_REALLOC_ARRAY( driver_info_3, DRIVER_INFO_3, *returned+ndrivers )) == NULL) {
5950
				DEBUG(0,("enumprinterdrivers_level3: failed to enlarge driver info buffer!\n"));
5950
				DEBUG(0,("enumprinterdrivers_level3: failed to enlarge driver info buffer!\n"));
5951
				SAFE_FREE(driver_info_3);
5951
				SAFE_FREE(driver_info_3);
5952
				SAFE_FREE(list);
5952
				SAFE_FREE(list);
Lines 6099-6105 Link Here
6099
6099
6100
	switch (level) {
6100
	switch (level) {
6101
	case 1:
6101
	case 1:
6102
		if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) {
6102
		if ((forms_1=SMB_MALLOC_ARRAY(FORM_1, *numofforms)) == NULL) {
6103
			*numofforms=0;
6103
			*numofforms=0;
6104
			return WERR_NOMEM;
6104
			return WERR_NOMEM;
6105
		}
6105
		}
Lines 6305-6311 Link Here
6305
		close(fd);
6305
		close(fd);
6306
6306
6307
		if(numlines) {
6307
		if(numlines) {
6308
			if((ports=(PORT_INFO_1 *)malloc( numlines * sizeof(PORT_INFO_1) )) == NULL) {
6308
			if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) {
6309
				DEBUG(10,("Returning WERR_NOMEM [%s]\n", 
6309
				DEBUG(10,("Returning WERR_NOMEM [%s]\n", 
6310
					  dos_errstr(WERR_NOMEM)));
6310
					  dos_errstr(WERR_NOMEM)));
6311
				file_lines_free(qlines);
6311
				file_lines_free(qlines);
Lines 6325-6331 Link Here
6325
	} else {
6325
	} else {
6326
		*returned = 1; /* Sole Samba port returned. */
6326
		*returned = 1; /* Sole Samba port returned. */
6327
6327
6328
		if((ports=(PORT_INFO_1 *)malloc( sizeof(PORT_INFO_1) )) == NULL)
6328
		if((ports=SMB_MALLOC_P(PORT_INFO_1)) == NULL)
6329
			return WERR_NOMEM;
6329
			return WERR_NOMEM;
6330
	
6330
	
6331
		DEBUG(10,("enumports_level_1: port name %s\n", SAMBA_PRINTER_PORT_NAME));
6331
		DEBUG(10,("enumports_level_1: port name %s\n", SAMBA_PRINTER_PORT_NAME));
Lines 6404-6410 Link Here
6404
		close(fd);
6404
		close(fd);
6405
6405
6406
		if(numlines) {
6406
		if(numlines) {
6407
			if((ports=(PORT_INFO_2 *)malloc( numlines * sizeof(PORT_INFO_2) )) == NULL) {
6407
			if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines )) == NULL) {
6408
				file_lines_free(qlines);
6408
				file_lines_free(qlines);
6409
				return WERR_NOMEM;
6409
				return WERR_NOMEM;
6410
			}
6410
			}
Lines 6423-6429 Link Here
6423
6423
6424
		*returned = 1;
6424
		*returned = 1;
6425
6425
6426
		if((ports=(PORT_INFO_2 *)malloc( sizeof(PORT_INFO_2) )) == NULL)
6426
		if((ports=SMB_MALLOC_P(PORT_INFO_2)) == NULL)
6427
			return WERR_NOMEM;
6427
			return WERR_NOMEM;
6428
	
6428
	
6429
		DEBUG(10,("enumports_level_2: port name %s\n", SAMBA_PRINTER_PORT_NAME));
6429
		DEBUG(10,("enumports_level_2: port name %s\n", SAMBA_PRINTER_PORT_NAME));
Lines 6504-6510 Link Here
6504
	int	snum;
6504
	int	snum;
6505
	WERROR err = WERR_OK;
6505
	WERROR err = WERR_OK;
6506
6506
6507
	if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) {
6507
	if ((printer = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL)) == NULL) {
6508
		DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
6508
		DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
6509
		return WERR_NOMEM;
6509
		return WERR_NOMEM;
6510
	}
6510
	}
Lines 6787-6793 Link Here
6787
	if (get_short_archi(short_archi, long_archi)==False)
6787
	if (get_short_archi(short_archi, long_archi)==False)
6788
		return WERR_INVALID_ENVIRONMENT;
6788
		return WERR_INVALID_ENVIRONMENT;
6789
6789
6790
	if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL)
6790
	if((info=SMB_MALLOC_P(DRIVER_DIRECTORY_1)) == NULL)
6791
		return WERR_NOMEM;
6791
		return WERR_NOMEM;
6792
6792
6793
	slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", get_called_name(), short_archi);
6793
	slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", get_called_name(), short_archi);
Lines 6942-6948 Link Here
6942
		   problems unmarshalling the response */
6942
		   problems unmarshalling the response */
6943
6943
6944
		*out_max_value_len=(in_value_len/sizeof(uint16));
6944
		*out_max_value_len=(in_value_len/sizeof(uint16));
6945
		if((*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL)
6945
		if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL)
6946
			return WERR_NOMEM;
6946
			return WERR_NOMEM;
6947
6947
6948
		*out_value_len = (uint32)dos_PutUniCode((char *)*out_value, "", in_value_len, True);
6948
		*out_value_len = (uint32)dos_PutUniCode((char *)*out_value, "", in_value_len, True);
Lines 6950-6956 Link Here
6950
		/* the data is counted in bytes */
6950
		/* the data is counted in bytes */
6951
		*out_max_data_len = in_data_len;
6951
		*out_max_data_len = in_data_len;
6952
		*out_data_len = in_data_len;
6952
		*out_data_len = in_data_len;
6953
		if((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL)
6953
		if((*data_out=(uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL)
6954
			return WERR_NOMEM;
6954
			return WERR_NOMEM;
6955
6955
6956
		return WERR_NO_MORE_ITEMS;
6956
		return WERR_NO_MORE_ITEMS;
Lines 6968-6974 Link Here
6968
	 */
6968
	 */
6969
	
6969
	
6970
	*out_max_value_len=(in_value_len/sizeof(uint16));
6970
	*out_max_value_len=(in_value_len/sizeof(uint16));
6971
	if((*out_value=(uint16 *)talloc_zero(p->mem_ctx,in_value_len*sizeof(uint8))) == NULL) {
6971
	if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx,in_value_len*sizeof(uint8))) == NULL) {
6972
		SAFE_FREE(data);
6972
		SAFE_FREE(data);
6973
		return WERR_NOMEM;
6973
		return WERR_NOMEM;
6974
	}
6974
	}
Lines 6979-6985 Link Here
6979
6979
6980
	/* the data is counted in bytes */
6980
	/* the data is counted in bytes */
6981
	*out_max_data_len=in_data_len;
6981
	*out_max_data_len=in_data_len;
6982
	if((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) {
6982
	if((*data_out=(uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) {
6983
		SAFE_FREE(data);
6983
		SAFE_FREE(data);
6984
		return WERR_NOMEM;
6984
		return WERR_NOMEM;
6985
	}
6985
	}
Lines 7366-7372 Link Here
7366
{
7366
{
7367
	PRINTPROCESSOR_1 *info_1=NULL;
7367
	PRINTPROCESSOR_1 *info_1=NULL;
7368
	
7368
	
7369
	if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL)
7369
	if((info_1 = SMB_MALLOC_P(PRINTPROCESSOR_1)) == NULL)
7370
		return WERR_NOMEM;
7370
		return WERR_NOMEM;
7371
7371
7372
	(*returned) = 0x1;
7372
	(*returned) = 0x1;
Lines 7435-7441 Link Here
7435
{
7435
{
7436
	PRINTPROCDATATYPE_1 *info_1=NULL;
7436
	PRINTPROCDATATYPE_1 *info_1=NULL;
7437
	
7437
	
7438
	if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL)
7438
	if((info_1 = SMB_MALLOC_P(PRINTPROCDATATYPE_1)) == NULL)
7439
		return WERR_NOMEM;
7439
		return WERR_NOMEM;
7440
7440
7441
	(*returned) = 0x1;
7441
	(*returned) = 0x1;
Lines 7497-7503 Link Here
7497
{
7497
{
7498
	PRINTMONITOR_1 *info_1=NULL;
7498
	PRINTMONITOR_1 *info_1=NULL;
7499
	
7499
	
7500
	if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL)
7500
	if((info_1 = SMB_MALLOC_P(PRINTMONITOR_1)) == NULL)
7501
		return WERR_NOMEM;
7501
		return WERR_NOMEM;
7502
7502
7503
	(*returned) = 0x1;
7503
	(*returned) = 0x1;
Lines 7529-7535 Link Here
7529
{
7529
{
7530
	PRINTMONITOR_2 *info_2=NULL;
7530
	PRINTMONITOR_2 *info_2=NULL;
7531
	
7531
	
7532
	if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL)
7532
	if((info_2 = SMB_MALLOC_P(PRINTMONITOR_2)) == NULL)
7533
		return WERR_NOMEM;
7533
		return WERR_NOMEM;
7534
7534
7535
	(*returned) = 0x1;
7535
	(*returned) = 0x1;
Lines 7602-7608 Link Here
7602
	BOOL found=False;
7602
	BOOL found=False;
7603
	JOB_INFO_1 *info_1=NULL;
7603
	JOB_INFO_1 *info_1=NULL;
7604
7604
7605
	info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
7605
	info_1=SMB_MALLOC_P(JOB_INFO_1);
7606
7606
7607
	if (info_1 == NULL) {
7607
	if (info_1 == NULL) {
7608
		SAFE_FREE(queue);
7608
		SAFE_FREE(queue);
Lines 7654-7660 Link Here
7654
	WERROR ret;
7654
	WERROR ret;
7655
	DEVICEMODE *devmode = NULL;
7655
	DEVICEMODE *devmode = NULL;
7656
7656
7657
	info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
7657
	info_2=SMB_MALLOC_P(JOB_INFO_2);
7658
7658
7659
	ZERO_STRUCTP(info_2);
7659
	ZERO_STRUCTP(info_2);
7660
7660
Lines 7785-7791 Link Here
7785
7785
7786
		
7786
		
7787
	if (!Printer) {
7787
	if (!Printer) {
7788
		if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL)
7788
		if((*data=(uint8 *)TALLOC_ZERO(p->mem_ctx, 4*sizeof(uint8))) == NULL)
7789
			return WERR_NOMEM;
7789
			return WERR_NOMEM;
7790
		DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
7790
		DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
7791
		return WERR_BADFID;
7791
		return WERR_BADFID;
Lines 7824-7830 Link Here
7824
		
7824
		
7825
		/* reply this param doesn't exist */
7825
		/* reply this param doesn't exist */
7826
		if (*out_size) {
7826
		if (*out_size) {
7827
			if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL)
7827
			if((*data=TALLOC_ZERO_ARRAY(p->mem_ctx, uint8, *out_size)) == NULL)
7828
				return WERR_NOMEM;
7828
				return WERR_NOMEM;
7829
		} else {
7829
		} else {
7830
			*data = NULL;
7830
			*data = NULL;
Lines 8008-8014 Link Here
8008
8008
8009
		DEBUG(10,("retrieved value number [%d] [%s]\n", num_entries, value));
8009
		DEBUG(10,("retrieved value number [%d] [%s]\n", num_entries, value));
8010
8010
8011
		if ((ptr=talloc_realloc(p->mem_ctx, enum_values, (num_entries+1) * sizeof(PRINTER_ENUM_VALUES))) == NULL)
8011
		if ((ptr=TALLOC_REALLOC_ARRAY(p->mem_ctx, enum_values, PRINTER_ENUM_VALUES, num_entries+1)) == NULL)
8012
		{
8012
		{
8013
			DEBUG(0,("talloc_realloc failed to allocate more memory!\n"));
8013
			DEBUG(0,("talloc_realloc failed to allocate more memory!\n"));
8014
			result = WERR_NOMEM;
8014
			result = WERR_NOMEM;
Lines 8026-8032 Link Here
8026
		
8026
		
8027
		if ( data_len )
8027
		if ( data_len )
8028
		{
8028
		{
8029
			if ( !(enum_values[num_entries].data = talloc_zero(p->mem_ctx, data_len)) ) {
8029
			if ( !(enum_values[num_entries].data = TALLOC_ZERO(p->mem_ctx, data_len)) ) {
8030
				DEBUG(0,("talloc_realloc failed to allocate more memory [data_len=%d] for data!\n", data_len ));
8030
				DEBUG(0,("talloc_realloc failed to allocate more memory [data_len=%d] for data!\n", data_len ));
8031
				result = WERR_NOMEM;
8031
				result = WERR_NOMEM;
8032
				goto done;
8032
				goto done;
Lines 8090-8096 Link Here
8090
	if (get_short_archi(short_archi, long_archi)==False)
8090
	if (get_short_archi(short_archi, long_archi)==False)
8091
		return WERR_INVALID_ENVIRONMENT;
8091
		return WERR_INVALID_ENVIRONMENT;
8092
8092
8093
	if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL)
8093
	if((info=SMB_MALLOC_P(PRINTPROCESSOR_DIRECTORY_1)) == NULL)
8094
		return WERR_NOMEM;
8094
		return WERR_NOMEM;
8095
8095
8096
	pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86");
8096
	pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86");
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_srvsvc_nt.c (-9 / +9 lines)
Lines 494-500 Link Here
494
		SRV_SHARE_INFO_1 *info1;
494
		SRV_SHARE_INFO_1 *info1;
495
		int i = 0;
495
		int i = 0;
496
496
497
		info1 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1));
497
		info1 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1, num_entries);
498
498
499
		for (snum = *resume_hnd; snum < num_services; snum++) {
499
		for (snum = *resume_hnd; snum < num_services; snum++) {
500
			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
500
			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
Lines 511-517 Link Here
511
		SRV_SHARE_INFO_2 *info2;
511
		SRV_SHARE_INFO_2 *info2;
512
		int i = 0;
512
		int i = 0;
513
513
514
		info2 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_2));
514
		info2 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_2, num_entries);
515
515
516
		for (snum = *resume_hnd; snum < num_services; snum++) {
516
		for (snum = *resume_hnd; snum < num_services; snum++) {
517
			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
517
			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
Lines 528-534 Link Here
528
		SRV_SHARE_INFO_501 *info501;
528
		SRV_SHARE_INFO_501 *info501;
529
		int i = 0;
529
		int i = 0;
530
	
530
	
531
		info501 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_501));
531
		info501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_501, num_entries);
532
532
533
		for (snum = *resume_hnd; snum < num_services; snum++) {
533
		for (snum = *resume_hnd; snum < num_services; snum++) {
534
			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
534
			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
Lines 545-551 Link Here
545
		SRV_SHARE_INFO_502 *info502;
545
		SRV_SHARE_INFO_502 *info502;
546
		int i = 0;
546
		int i = 0;
547
547
548
		info502 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_502));
548
		info502 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_502, num_entries);
549
549
550
		for (snum = *resume_hnd; snum < num_services; snum++) {
550
		for (snum = *resume_hnd; snum < num_services; snum++) {
551
			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
551
			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
Lines 1052-1058 Link Here
1052
WERROR _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R_NET_SRV_GET_INFO *r_u)
1052
WERROR _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R_NET_SRV_GET_INFO *r_u)
1053
{
1053
{
1054
	WERROR status = WERR_OK;
1054
	WERROR status = WERR_OK;
1055
	SRV_INFO_CTR *ctr = (SRV_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_INFO_CTR));
1055
	SRV_INFO_CTR *ctr = TALLOC_P(p->mem_ctx, SRV_INFO_CTR);
1056
1056
1057
	if (!ctr)
1057
	if (!ctr)
1058
		return WERR_NOMEM;
1058
		return WERR_NOMEM;
Lines 1124-1130 Link Here
1124
1124
1125
WERROR _srv_net_file_enum(pipes_struct *p, SRV_Q_NET_FILE_ENUM *q_u, SRV_R_NET_FILE_ENUM *r_u)
1125
WERROR _srv_net_file_enum(pipes_struct *p, SRV_Q_NET_FILE_ENUM *q_u, SRV_R_NET_FILE_ENUM *r_u)
1126
{
1126
{
1127
	r_u->ctr = (SRV_FILE_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_FILE_INFO_CTR));
1127
	r_u->ctr = TALLOC_P(p->mem_ctx, SRV_FILE_INFO_CTR);
1128
	if (!r_u->ctr)
1128
	if (!r_u->ctr)
1129
		return WERR_NOMEM;
1129
		return WERR_NOMEM;
1130
1130
Lines 1151-1157 Link Here
1151
{
1151
{
1152
	DEBUG(5,("srv_net_conn_enum: %d\n", __LINE__));
1152
	DEBUG(5,("srv_net_conn_enum: %d\n", __LINE__));
1153
1153
1154
	r_u->ctr = (SRV_CONN_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_CONN_INFO_CTR));
1154
	r_u->ctr = TALLOC_P(p->mem_ctx, SRV_CONN_INFO_CTR);
1155
	if (!r_u->ctr)
1155
	if (!r_u->ctr)
1156
		return WERR_NOMEM;
1156
		return WERR_NOMEM;
1157
1157
Lines 1176-1182 Link Here
1176
{
1176
{
1177
	DEBUG(5,("_srv_net_sess_enum: %d\n", __LINE__));
1177
	DEBUG(5,("_srv_net_sess_enum: %d\n", __LINE__));
1178
1178
1179
	r_u->ctr = (SRV_SESS_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_SESS_INFO_CTR));
1179
	r_u->ctr = TALLOC_P(p->mem_ctx, SRV_SESS_INFO_CTR);
1180
	if (!r_u->ctr)
1180
	if (!r_u->ctr)
1181
		return WERR_NOMEM;
1181
		return WERR_NOMEM;
1182
1182
Lines 1595-1601 Link Here
1595
	struct tm *t;
1595
	struct tm *t;
1596
	time_t unixdate = time(NULL);
1596
	time_t unixdate = time(NULL);
1597
1597
1598
	tod = (TIME_OF_DAY_INFO *)talloc(p->mem_ctx, sizeof(TIME_OF_DAY_INFO));
1598
	tod = TALLOC_P(p->mem_ctx, TIME_OF_DAY_INFO);
1599
	if (!tod)
1599
	if (!tod)
1600
		return WERR_NOMEM;
1600
		return WERR_NOMEM;
1601
1601
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_util.c (-1 / +1 lines)
Lines 97-103 Link Here
97
       count++)
97
       count++)
98
    ;
98
    ;
99
99
100
  gids = (DOM_GID *)talloc(ctx, sizeof(DOM_GID) * count );
100
  gids = TALLOC_ARRAY(ctx, DOM_GID, count );
101
  if(!gids)
101
  if(!gids)
102
  {
102
  {
103
    DEBUG(0,("make_dom_gids: talloc fail !\n"));
103
    DEBUG(0,("make_dom_gids: talloc fail !\n"));
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpc_server/srv_wkssvc_nt.c (-1 / +1 lines)
Lines 65-71 Link Here
65
65
66
	DEBUG(5,("_wks_query_info: %d\n", __LINE__));
66
	DEBUG(5,("_wks_query_info: %d\n", __LINE__));
67
67
68
	wks100 = (WKS_INFO_100 *)talloc_zero(p->mem_ctx, sizeof(WKS_INFO_100));
68
	wks100 = TALLOC_ZERO_P(p->mem_ctx, WKS_INFO_100);
69
69
70
	if (!wks100)
70
	if (!wks100)
71
		return NT_STATUS_NO_MEMORY;
71
		return NT_STATUS_NO_MEMORY;
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpcclient/cmd_lsarpc.c (-1 / +1 lines)
Lines 142-148 Link Here
142
142
143
	/* Convert arguments to sids */
143
	/* Convert arguments to sids */
144
144
145
	sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * (argc - 1));
145
	sids = TALLOC_ARRAY(mem_ctx, DOM_SID, argc - 1);
146
146
147
	if (!sids) {
147
	if (!sids) {
148
		printf("could not allocate memory for %d sids\n", argc - 1);
148
		printf("could not allocate memory for %d sids\n", argc - 1);
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpcclient/cmd_samr.c (-2 / +2 lines)
Lines 1045-1051 Link Here
1045
	/* Look up names */
1045
	/* Look up names */
1046
1046
1047
	num_names = argc - 2;
1047
	num_names = argc - 2;
1048
	names = (const char **)talloc(mem_ctx, sizeof(char *) * num_names);
1048
	names = (const char **)TALLOC_ARRAY(mem_ctx, char *, num_names);
1049
1049
1050
	for (i = 0; i < argc - 2; i++)
1050
	for (i = 0; i < argc - 2; i++)
1051
		names[i] = argv[i + 2];
1051
		names[i] = argv[i + 2];
Lines 1106-1112 Link Here
1106
	/* Look up rids */
1106
	/* Look up rids */
1107
1107
1108
	num_rids = argc - 1;
1108
	num_rids = argc - 1;
1109
	rids = (uint32 *)talloc(mem_ctx, sizeof(uint32) * num_rids);
1109
	rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids);
1110
1110
1111
	for (i = 0; i < argc - 1; i++)
1111
	for (i = 0; i < argc - 1; i++)
1112
                sscanf(argv[i + 1], "%i", &rids[i]);
1112
                sscanf(argv[i + 1], "%i", &rids[i]);
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpcclient/cmd_spoolss.c (-1 / +1 lines)
Lines 1031-1037 Link Here
1031
	/* allocate the space; add one extra slot for a terminating NULL.
1031
	/* allocate the space; add one extra slot for a terminating NULL.
1032
	   Each filename is NULL terminated and the end contains a double
1032
	   Each filename is NULL terminated and the end contains a double
1033
	   NULL */
1033
	   NULL */
1034
	if ((info->dependentfiles=(uint16*)talloc(mem_ctx, (len+1)*sizeof(uint16))) == NULL)
1034
	if ((info->dependentfiles=TALLOC_ARRAY(mem_ctx, uint16, len+1)) == NULL)
1035
	{
1035
	{
1036
		DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));
1036
		DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));
1037
		return False;
1037
		return False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/rpcclient/rpcclient.c (-7 / +7 lines)
Lines 54-63 Link Here
54
	if (!commands) 
54
	if (!commands) 
55
		return NULL;
55
		return NULL;
56
56
57
	matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
57
	matches = SMB_MALLOC_ARRAY( char *, MAX_COMPLETIONS );
58
	if (!matches) return NULL;
58
	if (!matches) return NULL;
59
59
60
	matches[count++] = strdup(text);
60
	matches[count++] = SMB_STRDUP(text);
61
	if (!matches[0]) return NULL;
61
	if (!matches[0]) return NULL;
62
62
63
	while (commands && count < MAX_COMPLETIONS-1) 
63
	while (commands && count < MAX_COMPLETIONS-1) 
Lines 70-76 Link Here
70
			if ((strncmp(text, commands->cmd_set[i].name, strlen(text)) == 0) &&
70
			if ((strncmp(text, commands->cmd_set[i].name, strlen(text)) == 0) &&
71
				commands->cmd_set[i].fn) 
71
				commands->cmd_set[i].fn) 
72
			{
72
			{
73
				matches[count] = strdup(commands->cmd_set[i].name);
73
				matches[count] = SMB_STRDUP(commands->cmd_set[i].name);
74
				if (!matches[count]) 
74
				if (!matches[count]) 
75
					return NULL;
75
					return NULL;
76
				count++;
76
				count++;
Lines 83-89 Link Here
83
83
84
	if (count == 2) {
84
	if (count == 2) {
85
		SAFE_FREE(matches[0]);
85
		SAFE_FREE(matches[0]);
86
		matches[0] = strdup(matches[1]);
86
		matches[0] = SMB_STRDUP(matches[1]);
87
	}
87
	}
88
	matches[count] = NULL;
88
	matches[count] = NULL;
89
	return matches;
89
	return matches;
Lines 427-433 Link Here
427
{
427
{
428
	struct cmd_list *entry;
428
	struct cmd_list *entry;
429
429
430
	if (!(entry = (struct cmd_list *)malloc(sizeof(struct cmd_list)))) {
430
	if (!(entry = SMB_MALLOC_P(struct cmd_list))) {
431
		DEBUG(0, ("out of memory\n"));
431
		DEBUG(0, ("out of memory\n"));
432
		return;
432
		return;
433
	}
433
	}
Lines 453-459 Link Here
453
 again:
453
 again:
454
	while(next_token(&p, buf, " ", sizeof(buf))) {
454
	while(next_token(&p, buf, " ", sizeof(buf))) {
455
		if (argv) {
455
		if (argv) {
456
			argv[argc] = strdup(buf);
456
			argv[argc] = SMB_STRDUP(buf);
457
		}
457
		}
458
		
458
		
459
		argc++;
459
		argc++;
Lines 463-469 Link Here
463
463
464
		/* Create argument list */
464
		/* Create argument list */
465
465
466
		argv = (char **)malloc(sizeof(char *) * argc);
466
		argv = SMB_MALLOC_ARRAY( char *, argc );
467
                memset(argv, 0, sizeof(char *) * argc);
467
                memset(argv, 0, sizeof(char *) * argc);
468
468
469
		if (!argv) {
469
		if (!argv) {
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/blocking.c (-2 / +2 lines)
Lines 103-114 Link Here
103
   * the expiration time here.
103
   * the expiration time here.
104
   */
104
   */
105
105
106
  if((blr = (blocking_lock_record *)malloc(sizeof(blocking_lock_record))) == NULL) {
106
  if((blr = SMB_MALLOC_P(blocking_lock_record)) == NULL) {
107
    DEBUG(0,("push_blocking_lock_request: Malloc fail !\n" ));
107
    DEBUG(0,("push_blocking_lock_request: Malloc fail !\n" ));
108
    return False;
108
    return False;
109
  }
109
  }
110
110
111
  if((blr->inbuf = (char *)malloc(length)) == NULL) {
111
  if((blr->inbuf = (char *)SMB_MALLOC(length)) == NULL) {
112
    DEBUG(0,("push_blocking_lock_request: Malloc fail (2)!\n" ));
112
    DEBUG(0,("push_blocking_lock_request: Malloc fail (2)!\n" ));
113
    SAFE_FREE(blr);
113
    SAFE_FREE(blr);
114
    return False;
114
    return False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/conn.c (-1 / +1 lines)
Lines 126-132 Link Here
126
                goto find_again;
126
                goto find_again;
127
	}
127
	}
128
128
129
	conn = (connection_struct *)malloc(sizeof(*conn));
129
	conn = SMB_MALLOC_P(connection_struct);
130
	if (!conn) return NULL;
130
	if (!conn) return NULL;
131
131
132
	ZERO_STRUCTP(conn);
132
	ZERO_STRUCTP(conn);
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/dir.c (-4 / +4 lines)
Lines 407-413 Link Here
407
  if (dptrs_open >= MAX_OPEN_DIRECTORIES)
407
  if (dptrs_open >= MAX_OPEN_DIRECTORIES)
408
    dptr_idleoldest();
408
    dptr_idleoldest();
409
409
410
  dptr = (dptr_struct *)malloc(sizeof(dptr_struct));
410
  dptr = SMB_MALLOC_P(dptr_struct);
411
  if(!dptr) {
411
  if(!dptr) {
412
    DEBUG(0,("malloc fail in dptr_create.\n"));
412
    DEBUG(0,("malloc fail in dptr_create.\n"));
413
    return -1;
413
    return -1;
Lines 752-758 Link Here
752
  
752
  
753
	if (!p)
753
	if (!p)
754
		return(NULL);
754
		return(NULL);
755
	dirp = (Dir *)malloc(sizeof(Dir));
755
	dirp = SMB_MALLOC_P(Dir);
756
	if (!dirp) {
756
	if (!dirp) {
757
		DEBUG(0,("Out of memory in OpenDir\n"));
757
		DEBUG(0,("Out of memory in OpenDir\n"));
758
		conn->vfs_ops.closedir(conn,p);
758
		conn->vfs_ops.closedir(conn,p);
Lines 806-812 Link Here
806
		if (used + l > dirp->mallocsize) {
806
		if (used + l > dirp->mallocsize) {
807
			int s = MAX(used+l,used+2000);
807
			int s = MAX(used+l,used+2000);
808
			char *r;
808
			char *r;
809
			r = (char *)Realloc(dirp->data,s);
809
			r = (char *)SMB_REALLOC(dirp->data,s);
810
			if (!r) {
810
			if (!r) {
811
				DEBUG(0,("Out of memory in OpenDir\n"));
811
				DEBUG(0,("Out of memory in OpenDir\n"));
812
				break;
812
				break;
Lines 924-930 Link Here
924
   */
924
   */
925
  pathlen = strlen( path ) +1;  /* Bytes required to store path (with nul). */
925
  pathlen = strlen( path ) +1;  /* Bytes required to store path (with nul). */
926
  namelen = strlen( name ) +1;  /* Bytes required to store name (with nul). */
926
  namelen = strlen( name ) +1;  /* Bytes required to store name (with nul). */
927
  entry = (dir_cache_entry *)malloc( sizeof( dir_cache_entry )
927
  entry = (dir_cache_entry *)SMB_MALLOC( sizeof( dir_cache_entry )
928
                                   + pathlen
928
                                   + pathlen
929
                                   + namelen
929
                                   + namelen
930
                                   + strlen( dname ) +1 );
930
                                   + strlen( dname ) +1 );
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/fileio.c (-2 / +2 lines)
Lines 660-666 Link Here
660
	if(alloc_size == 0 || fsp->wcp)
660
	if(alloc_size == 0 || fsp->wcp)
661
		return False;
661
		return False;
662
662
663
	if((wcp = (write_cache *)malloc(sizeof(write_cache))) == NULL) {
663
	if((wcp = SMB_MALLOC_P(write_cache)) == NULL) {
664
		DEBUG(0,("setup_write_cache: malloc fail.\n"));
664
		DEBUG(0,("setup_write_cache: malloc fail.\n"));
665
		return False;
665
		return False;
666
	}
666
	}
Lines 669-675 Link Here
669
	wcp->offset = 0;
669
	wcp->offset = 0;
670
	wcp->alloc_size = alloc_size;
670
	wcp->alloc_size = alloc_size;
671
	wcp->data_size = 0;
671
	wcp->data_size = 0;
672
	if((wcp->data = malloc(wcp->alloc_size)) == NULL) {
672
	if((wcp->data = SMB_MALLOC(wcp->alloc_size)) == NULL) {
673
		DEBUG(0,("setup_write_cache: malloc fail for buffer size %u.\n",
673
		DEBUG(0,("setup_write_cache: malloc fail for buffer size %u.\n",
674
			(unsigned int)wcp->alloc_size ));
674
			(unsigned int)wcp->alloc_size ));
675
		SAFE_FREE(wcp);
675
		SAFE_FREE(wcp);
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/files.c (-1 / +1 lines)
Lines 94-100 Link Here
94
		return NULL;
94
		return NULL;
95
	}
95
	}
96
96
97
	fsp = (files_struct *)malloc(sizeof(*fsp));
97
	fsp = SMB_MALLOC_P(files_struct);
98
	if (!fsp) {
98
	if (!fsp) {
99
		unix_ERR_class = ERRSRV;
99
		unix_ERR_class = ERRSRV;
100
		unix_ERR_code = ERRnofids;
100
		unix_ERR_code = ERRnofids;
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/ipc.c (-4 / +4 lines)
Lines 174-180 Link Here
174
174
175
static BOOL api_rpc_trans_reply(char *outbuf, pipes_struct *p)
175
static BOOL api_rpc_trans_reply(char *outbuf, pipes_struct *p)
176
{
176
{
177
	char *rdata = malloc(p->max_trans_reply);
177
	char *rdata = SMB_MALLOC(p->max_trans_reply);
178
	int data_len;
178
	int data_len;
179
179
180
	if(rdata == NULL) {
180
	if(rdata == NULL) {
Lines 389-395 Link Here
389
		goto bad_param;
389
		goto bad_param;
390
  
390
  
391
	if (tdscnt)  {
391
	if (tdscnt)  {
392
		if((data = (char *)malloc(tdscnt)) == NULL) {
392
		if((data = (char *)SMB_MALLOC(tdscnt)) == NULL) {
393
			DEBUG(0,("reply_trans: data malloc fail for %u bytes !\n", tdscnt));
393
			DEBUG(0,("reply_trans: data malloc fail for %u bytes !\n", tdscnt));
394
			END_PROFILE(SMBtrans);
394
			END_PROFILE(SMBtrans);
395
			return(ERROR_DOS(ERRDOS,ERRnomem));
395
			return(ERROR_DOS(ERRDOS,ERRnomem));
Lines 403-409 Link Here
403
	}
403
	}
404
404
405
	if (tpscnt) {
405
	if (tpscnt) {
406
		if((params = (char *)malloc(tpscnt)) == NULL) {
406
		if((params = (char *)SMB_MALLOC(tpscnt)) == NULL) {
407
			DEBUG(0,("reply_trans: param malloc fail for %u bytes !\n", tpscnt));
407
			DEBUG(0,("reply_trans: param malloc fail for %u bytes !\n", tpscnt));
408
			SAFE_FREE(data);
408
			SAFE_FREE(data);
409
			END_PROFILE(SMBtrans);
409
			END_PROFILE(SMBtrans);
Lines 419-425 Link Here
419
419
420
	if (suwcnt) {
420
	if (suwcnt) {
421
		int i;
421
		int i;
422
		if((setup = (uint16 *)malloc(suwcnt*sizeof(uint16))) == NULL) {
422
		if((setup = SMB_MALLOC_ARRAY(uint16, suwcnt)) == NULL) {
423
			DEBUG(0,("reply_trans: setup malloc fail for %u bytes !\n", (unsigned int)(suwcnt * sizeof(uint16))));
423
			DEBUG(0,("reply_trans: setup malloc fail for %u bytes !\n", (unsigned int)(suwcnt * sizeof(uint16))));
424
			SAFE_FREE(data);
424
			SAFE_FREE(data);
425
			SAFE_FREE(params);
425
			SAFE_FREE(params);
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/lanman.c (-57 / +56 lines)
Lines 894-900 Link Here
894
		 */
894
		 */
895
		*rdata_len = 0;
895
		*rdata_len = 0;
896
		*rparam_len = 6;
896
		*rparam_len = 6;
897
		*rparam = REALLOC(*rparam,*rparam_len);
897
		*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
898
		SSVALS(*rparam,0,ERRunknownlevel);
898
		SSVALS(*rparam,0,ERRunknownlevel);
899
		SSVAL(*rparam,2,0);
899
		SSVAL(*rparam,2,0);
900
		SSVAL(*rparam,4,0);
900
		SSVAL(*rparam,4,0);
Lines 921-927 Link Here
921
	}
921
	}
922
922
923
	if (mdrcnt > 0) {
923
	if (mdrcnt > 0) {
924
		*rdata = REALLOC(*rdata,mdrcnt);
924
		*rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
925
		desc.base = *rdata;
925
		desc.base = *rdata;
926
		desc.buflen = mdrcnt;
926
		desc.buflen = mdrcnt;
927
	} else {
927
	} else {
Lines 930-936 Link Here
930
		 * init_package will return wrong size if buflen=0
930
		 * init_package will return wrong size if buflen=0
931
		 */
931
		 */
932
		desc.buflen = getlen(desc.format);
932
		desc.buflen = getlen(desc.format);
933
		desc.base = tmpdata = (char *) malloc (desc.buflen);
933
		desc.base = tmpdata = (char *) SMB_MALLOC (desc.buflen);
934
	}
934
	}
935
935
936
	if (init_package(&desc,1,count)) {
936
	if (init_package(&desc,1,count)) {
Lines 949-955 Link Here
949
	*rdata_len = desc.usedlen;
949
	*rdata_len = desc.usedlen;
950
  
950
  
951
	*rparam_len = 6;
951
	*rparam_len = 6;
952
	*rparam = REALLOC(*rparam,*rparam_len);
952
	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
953
	SSVALS(*rparam,0,desc.errcode);
953
	SSVALS(*rparam,0,desc.errcode);
954
	SSVAL(*rparam,2,0);
954
	SSVAL(*rparam,2,0);
955
	SSVAL(*rparam,4,desc.neededlen);
955
	SSVAL(*rparam,4,desc.neededlen);
Lines 997-1003 Link Here
997
     */
997
     */
998
    *rdata_len = 0;
998
    *rdata_len = 0;
999
    *rparam_len = 6;
999
    *rparam_len = 6;
1000
    *rparam = REALLOC(*rparam,*rparam_len);
1000
    *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1001
    SSVALS(*rparam,0,ERRunknownlevel);
1001
    SSVALS(*rparam,0,ERRunknownlevel);
1002
    SSVAL(*rparam,2,0);
1002
    SSVAL(*rparam,2,0);
1003
    SSVAL(*rparam,4,0);
1003
    SSVAL(*rparam,4,0);
Lines 1009-1025 Link Here
1009
    if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i))
1009
    if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i))
1010
      queuecnt++;
1010
      queuecnt++;
1011
  if (uLevel > 0) {
1011
  if (uLevel > 0) {
1012
    if((queue = (print_queue_struct**)malloc(queuecnt*sizeof(print_queue_struct*))) == NULL) {
1012
    if((queue = SMB_MALLOC_ARRAY(print_queue_struct *, queuecnt)) == NULL) {
1013
      DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1013
      DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1014
      return False;
1014
      return False;
1015
    }
1015
    }
1016
    memset(queue,0,queuecnt*sizeof(print_queue_struct*));
1016
    memset(queue,0,queuecnt*sizeof(print_queue_struct*));
1017
    if((status = (print_status_struct*)malloc(queuecnt*sizeof(print_status_struct))) == NULL) {
1017
    if((status = SMB_MALLOC_ARRAY(print_status_struct, queuecnt)) == NULL) {
1018
      DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1018
      DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1019
      return False;
1019
      return False;
1020
    }
1020
    }
1021
    memset(status,0,queuecnt*sizeof(print_status_struct));
1021
    memset(status,0,queuecnt*sizeof(print_status_struct));
1022
    if((subcntarr = (int*)malloc(queuecnt*sizeof(int))) == NULL) {
1022
    if((subcntarr = SMB_MALLOC_ARRAY(int, queuecnt)) == NULL) {
1023
      DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1023
      DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1024
      return False;
1024
      return False;
1025
    }
1025
    }
Lines 1032-1038 Link Here
1032
 	n++;
1032
 	n++;
1033
      }
1033
      }
1034
  }
1034
  }
1035
  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
1035
  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
1036
  desc.base = *rdata;
1036
  desc.base = *rdata;
1037
  desc.buflen = mdrcnt;
1037
  desc.buflen = mdrcnt;
1038
1038
Lines 1051-1057 Link Here
1051
 
1051
 
1052
  *rdata_len = desc.usedlen;
1052
  *rdata_len = desc.usedlen;
1053
  *rparam_len = 8;
1053
  *rparam_len = 8;
1054
  *rparam = REALLOC(*rparam,*rparam_len);
1054
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1055
  SSVALS(*rparam,0,desc.errcode);
1055
  SSVALS(*rparam,0,desc.errcode);
1056
  SSVAL(*rparam,2,0);
1056
  SSVAL(*rparam,2,0);
1057
  SSVAL(*rparam,4,succnt);
1057
  SSVAL(*rparam,4,succnt);
Lines 1135-1142 Link Here
1135
      struct srv_info_struct *ts;
1135
      struct srv_info_struct *ts;
1136
1136
1137
      alloced += 10;
1137
      alloced += 10;
1138
      ts = (struct srv_info_struct *)
1138
      ts = SMB_REALLOC_ARRAY(*servers, struct srv_info_struct, alloced);
1139
	Realloc(*servers,sizeof(**servers)*alloced);
1140
      if (!ts) {
1139
      if (!ts) {
1141
        DEBUG(0,("get_server_info: failed to enlarge servers info struct!\n"));
1140
        DEBUG(0,("get_server_info: failed to enlarge servers info struct!\n"));
1142
        return(0);
1141
        return(0);
Lines 1382-1388 Link Here
1382
  }
1381
  }
1383
1382
1384
  *rdata_len = fixed_len + string_len;
1383
  *rdata_len = fixed_len + string_len;
1385
  *rdata = REALLOC(*rdata,*rdata_len);
1384
  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
1386
  memset(*rdata,'\0',*rdata_len);
1385
  memset(*rdata,'\0',*rdata_len);
1387
  
1386
  
1388
  p2 = (*rdata) + fixed_len;	/* auxilliary data (strings) will go here */
1387
  p2 = (*rdata) + fixed_len;	/* auxilliary data (strings) will go here */
Lines 1406-1412 Link Here
1406
  }
1405
  }
1407
  
1406
  
1408
  *rparam_len = 8;
1407
  *rparam_len = 8;
1409
  *rparam = REALLOC(*rparam,*rparam_len);
1408
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1410
  SSVAL(*rparam,0,(missed == 0 ? NERR_Success : ERRmoredata));
1409
  SSVAL(*rparam,0,(missed == 0 ? NERR_Success : ERRmoredata));
1411
  SSVAL(*rparam,2,0);
1410
  SSVAL(*rparam,2,0);
1412
  SSVAL(*rparam,4,counted);
1411
  SSVAL(*rparam,4,counted);
Lines 1443-1449 Link Here
1443
  *rdata_len = 0;
1442
  *rdata_len = 0;
1444
  
1443
  
1445
  *rparam_len = 8;
1444
  *rparam_len = 8;
1446
  *rparam = REALLOC(*rparam,*rparam_len);
1445
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1447
1446
1448
  SSVAL(*rparam,0,0x08AC); /* informational warning message */
1447
  SSVAL(*rparam,0,0x08AC); /* informational warning message */
1449
  SSVAL(*rparam,2,0);
1448
  SSVAL(*rparam,2,0);
Lines 1589-1601 Link Here
1589
  if (!prefix_ok(str1,"zWrLh")) return False;
1588
  if (!prefix_ok(str1,"zWrLh")) return False;
1590
  if (!check_share_info(uLevel,str2)) return False;
1589
  if (!check_share_info(uLevel,str2)) return False;
1591
 
1590
 
1592
  *rdata = REALLOC(*rdata,mdrcnt);
1591
  *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
1593
  p = *rdata;
1592
  p = *rdata;
1594
  *rdata_len = fill_share_info(conn,snum,uLevel,&p,&mdrcnt,0,0,0);
1593
  *rdata_len = fill_share_info(conn,snum,uLevel,&p,&mdrcnt,0,0,0);
1595
  if (*rdata_len < 0) return False;
1594
  if (*rdata_len < 0) return False;
1596
 
1595
 
1597
  *rparam_len = 6;
1596
  *rparam_len = 6;
1598
  *rparam = REALLOC(*rparam,*rparam_len);
1597
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1599
  SSVAL(*rparam,0,NERR_Success);
1598
  SSVAL(*rparam,0,NERR_Success);
1600
  SSVAL(*rparam,2,0);		/* converter word */
1599
  SSVAL(*rparam,2,0);		/* converter word */
1601
  SSVAL(*rparam,4,*rdata_len);
1600
  SSVAL(*rparam,4,*rdata_len);
Lines 1643-1649 Link Here
1643
        missed = True;
1642
        missed = True;
1644
    }
1643
    }
1645
  *rdata_len = fixed_len + string_len;
1644
  *rdata_len = fixed_len + string_len;
1646
  *rdata = REALLOC(*rdata,*rdata_len);
1645
  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
1647
  memset(*rdata,0,*rdata_len);
1646
  memset(*rdata,0,*rdata_len);
1648
  
1647
  
1649
  p2 = (*rdata) + fixed_len;	/* auxillery data (strings) will go here */
1648
  p2 = (*rdata) + fixed_len;	/* auxillery data (strings) will go here */
Lines 1656-1662 Link Here
1656
 	break;
1655
 	break;
1657
  
1656
  
1658
  *rparam_len = 8;
1657
  *rparam_len = 8;
1659
  *rparam = REALLOC(*rparam,*rparam_len);
1658
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1660
  SSVAL(*rparam,0,missed ? ERRmoredata : NERR_Success);
1659
  SSVAL(*rparam,0,missed ? ERRmoredata : NERR_Success);
1661
  SSVAL(*rparam,2,0);
1660
  SSVAL(*rparam,2,0);
1662
  SSVAL(*rparam,4,counted);
1661
  SSVAL(*rparam,4,counted);
Lines 1680-1689 Link Here
1680
{
1679
{
1681
  char *p;
1680
  char *p;
1682
  *rparam_len = 4;
1681
  *rparam_len = 4;
1683
  *rparam = REALLOC(*rparam,*rparam_len);
1682
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1684
1683
1685
  *rdata_len = 21;
1684
  *rdata_len = 21;
1686
  *rdata = REALLOC(*rdata,*rdata_len);
1685
  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
1687
1686
1688
  SSVAL(*rparam,0,NERR_Success);
1687
  SSVAL(*rparam,0,NERR_Success);
1689
  SSVAL(*rparam,2,0);		/* converter word */
1688
  SSVAL(*rparam,2,0);		/* converter word */
Lines 1742-1748 Link Here
1742
  memcpy(pass2,p+16,16);
1741
  memcpy(pass2,p+16,16);
1743
1742
1744
  *rparam_len = 4;
1743
  *rparam_len = 4;
1745
  *rparam = REALLOC(*rparam,*rparam_len);
1744
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1746
1745
1747
  *rdata_len = 0;
1746
  *rdata_len = 0;
1748
1747
Lines 1852-1858 Link Here
1852
  fstring user;
1851
  fstring user;
1853
  char *p = param + 2;
1852
  char *p = param + 2;
1854
  *rparam_len = 2;
1853
  *rparam_len = 2;
1855
  *rparam = REALLOC(*rparam,*rparam_len);
1854
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1856
1855
1857
  *rdata_len = 0;
1856
  *rdata_len = 0;
1858
1857
Lines 1922-1928 Link Here
1922
		return(False);
1921
		return(False);
1923
1922
1924
	*rparam_len = 4;
1923
	*rparam_len = 4;
1925
	*rparam = REALLOC(*rparam,*rparam_len);	
1924
	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);	
1926
	*rdata_len = 0;
1925
	*rdata_len = 0;
1927
1926
1928
	if (!print_job_exists(jobid)) {
1927
	if (!print_job_exists(jobid)) {
Lines 1979-1985 Link Here
1979
		return(False);
1978
		return(False);
1980
1979
1981
	*rparam_len = 4;
1980
	*rparam_len = 4;
1982
	*rparam = REALLOC(*rparam,*rparam_len);
1981
	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
1983
	*rdata_len = 0;
1982
	*rdata_len = 0;
1984
1983
1985
	snum = print_queue_snum(QueueName);
1984
	snum = print_queue_snum(QueueName);
Lines 2049-2055 Link Here
2049
2048
2050
	jobid = SVAL(p,0);
2049
	jobid = SVAL(p,0);
2051
	*rparam_len = 4;
2050
	*rparam_len = 4;
2052
	*rparam = REALLOC(*rparam,*rparam_len);
2051
	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
2053
  
2052
  
2054
	*rdata_len = 0;
2053
	*rdata_len = 0;
2055
	
2054
	
Lines 2144-2150 Link Here
2144
  }
2143
  }
2145
2144
2146
  *rdata_len = mdrcnt;
2145
  *rdata_len = mdrcnt;
2147
  *rdata = REALLOC(*rdata,*rdata_len);
2146
  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
2148
2147
2149
  p = *rdata;
2148
  p = *rdata;
2150
  p2 = p + struct_len;
2149
  p2 = p + struct_len;
Lines 2193-2199 Link Here
2193
  *rdata_len = PTR_DIFF(p2,*rdata);
2192
  *rdata_len = PTR_DIFF(p2,*rdata);
2194
2193
2195
  *rparam_len = 6;
2194
  *rparam_len = 6;
2196
  *rparam = REALLOC(*rparam,*rparam_len);
2195
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
2197
  SSVAL(*rparam,0,NERR_Success);
2196
  SSVAL(*rparam,0,NERR_Success);
2198
  SSVAL(*rparam,2,0);		/* converter word */
2197
  SSVAL(*rparam,2,0);		/* converter word */
2199
  SSVAL(*rparam,4,*rdata_len);
2198
  SSVAL(*rparam,4,*rdata_len);
Lines 2220-2233 Link Here
2220
  DEBUG(4,("NetWkstaGetInfo level %d\n",level));
2219
  DEBUG(4,("NetWkstaGetInfo level %d\n",level));
2221
2220
2222
  *rparam_len = 6;
2221
  *rparam_len = 6;
2223
  *rparam = REALLOC(*rparam,*rparam_len);
2222
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
2224
2223
2225
  /* check it's a supported varient */
2224
  /* check it's a supported varient */
2226
  if (!(level==10 && strcsequal(str1,"WrLh") && strcsequal(str2,"zzzBBzz")))
2225
  if (!(level==10 && strcsequal(str1,"WrLh") && strcsequal(str2,"zzzBBzz")))
2227
    return(False);
2226
    return(False);
2228
2227
2229
  *rdata_len = mdrcnt + 1024;
2228
  *rdata_len = mdrcnt + 1024;
2230
  *rdata = REALLOC(*rdata,*rdata_len);
2229
  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
2231
2230
2232
  SSVAL(*rparam,0,NERR_Success);
2231
  SSVAL(*rparam,0,NERR_Success);
2233
  SSVAL(*rparam,2,0);		/* converter word */
2232
  SSVAL(*rparam,2,0);		/* converter word */
Lines 2466-2472 Link Here
2466
	       vuser->user.unix_name));
2465
	       vuser->user.unix_name));
2467
2466
2468
    *rparam_len = 6;
2467
    *rparam_len = 6;
2469
    *rparam = REALLOC(*rparam,*rparam_len);
2468
    *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
2470
2469
2471
    DEBUG(4,("RNetUserGetInfo level=%d\n", uLevel));
2470
    DEBUG(4,("RNetUserGetInfo level=%d\n", uLevel));
2472
  
2471
  
Lines 2485-2491 Link Here
2485
	if (strcmp(level_string,str2) != 0) return False;
2484
	if (strcmp(level_string,str2) != 0) return False;
2486
2485
2487
	*rdata_len = mdrcnt + 1024;
2486
	*rdata_len = mdrcnt + 1024;
2488
	*rdata = REALLOC(*rdata,*rdata_len);
2487
	*rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
2489
2488
2490
	SSVAL(*rparam,0,NERR_Success);
2489
	SSVAL(*rparam,0,NERR_Success);
2491
	SSVAL(*rparam,2,0);		/* converter word */
2490
	SSVAL(*rparam,2,0);		/* converter word */
Lines 2624-2630 Link Here
2624
  int count=0;
2623
  int count=0;
2625
2624
2626
  *rparam_len = 8;
2625
  *rparam_len = 8;
2627
  *rparam = REALLOC(*rparam,*rparam_len);
2626
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
2628
2627
2629
  /* check it's a supported varient */
2628
  /* check it's a supported varient */
2630
  if (strcmp(str1,"zWrLeh") != 0) return False;
2629
  if (strcmp(str1,"zWrLeh") != 0) return False;
Lines 2635-2641 Link Here
2635
  if (strcmp(level_string,str2) != 0) return False;
2634
  if (strcmp(level_string,str2) != 0) return False;
2636
2635
2637
  *rdata_len = mdrcnt + 1024;
2636
  *rdata_len = mdrcnt + 1024;
2638
  *rdata = REALLOC(*rdata,*rdata_len);
2637
  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
2639
2638
2640
  SSVAL(*rparam,0,NERR_Success);
2639
  SSVAL(*rparam,0,NERR_Success);
2641
  SSVAL(*rparam,2,0);		/* converter word */
2640
  SSVAL(*rparam,2,0);		/* converter word */
Lines 2679-2685 Link Here
2679
  /* check it's a supported varient */
2678
  /* check it's a supported varient */
2680
  if (strcmp(str1,"OOWb54WrLh") != 0) return False;
2679
  if (strcmp(str1,"OOWb54WrLh") != 0) return False;
2681
  if (uLevel != 1 || strcmp(str2,"WB21BWDWWDDDDDDDzzzD") != 0) return False;
2680
  if (uLevel != 1 || strcmp(str2,"WB21BWDWWDDDDDDDzzzD") != 0) return False;
2682
  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
2681
  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
2683
  desc.base = *rdata;
2682
  desc.base = *rdata;
2684
  desc.buflen = mdrcnt;
2683
  desc.buflen = mdrcnt;
2685
  desc.subformat = NULL;
2684
  desc.subformat = NULL;
Lines 2726-2732 Link Here
2726
2725
2727
  *rdata_len = desc.usedlen;
2726
  *rdata_len = desc.usedlen;
2728
  *rparam_len = 6;
2727
  *rparam_len = 6;
2729
  *rparam = REALLOC(*rparam,*rparam_len);
2728
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
2730
  SSVALS(*rparam,0,desc.errcode);
2729
  SSVALS(*rparam,0,desc.errcode);
2731
  SSVAL(*rparam,2,0);
2730
  SSVAL(*rparam,2,0);
2732
  SSVAL(*rparam,4,desc.neededlen);
2731
  SSVAL(*rparam,4,desc.neededlen);
Lines 2756-2762 Link Here
2756
  if (strcmp(str2,"") != 0) return False;
2755
  if (strcmp(str2,"") != 0) return False;
2757
2756
2758
  *rparam_len = 6;
2757
  *rparam_len = 6;
2759
  *rparam = REALLOC(*rparam,*rparam_len);
2758
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
2760
  SSVALS(*rparam,0,0);		/* errorcode */
2759
  SSVALS(*rparam,0,0);		/* errorcode */
2761
  SSVAL(*rparam,2,0);		/* converter word */
2760
  SSVAL(*rparam,2,0);		/* converter word */
2762
  SSVAL(*rparam,4,0x7f);	/* permission flags */
2761
  SSVAL(*rparam,4,0x7f);	/* permission flags */
Lines 2807-2813 Link Here
2807
  }
2806
  }
2808
2807
2809
  if (mdrcnt > 0) {
2808
  if (mdrcnt > 0) {
2810
    *rdata = REALLOC(*rdata,mdrcnt);
2809
    *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
2811
    desc.base = *rdata;
2810
    desc.base = *rdata;
2812
    desc.buflen = mdrcnt;
2811
    desc.buflen = mdrcnt;
2813
  } else {
2812
  } else {
Lines 2816-2822 Link Here
2816
     *  init_package will return wrong size if buflen=0
2815
     *  init_package will return wrong size if buflen=0
2817
     */
2816
     */
2818
    desc.buflen = getlen(desc.format);
2817
    desc.buflen = getlen(desc.format);
2819
    desc.base = tmpdata = (char *)malloc ( desc.buflen );
2818
    desc.base = tmpdata = (char *)SMB_MALLOC ( desc.buflen );
2820
  }
2819
  }
2821
2820
2822
  if (init_package(&desc,1,0)) {
2821
  if (init_package(&desc,1,0)) {
Lines 2831-2837 Link Here
2831
  }
2830
  }
2832
2831
2833
  *rparam_len = 6;
2832
  *rparam_len = 6;
2834
  *rparam = REALLOC(*rparam,*rparam_len);
2833
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
2835
  SSVALS(*rparam,0,desc.errcode);
2834
  SSVALS(*rparam,0,desc.errcode);
2836
  SSVAL(*rparam,2,0);
2835
  SSVAL(*rparam,2,0);
2837
  SSVAL(*rparam,4,desc.neededlen);
2836
  SSVAL(*rparam,4,desc.neededlen);
Lines 2885-2891 Link Here
2885
  if (snum < 0 || !VALID_SNUM(snum)) return(False);
2884
  if (snum < 0 || !VALID_SNUM(snum)) return(False);
2886
2885
2887
  count = print_queue_status(snum,&queue,&status);
2886
  count = print_queue_status(snum,&queue,&status);
2888
  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
2887
  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
2889
  desc.base = *rdata;
2888
  desc.base = *rdata;
2890
  desc.buflen = mdrcnt;
2889
  desc.buflen = mdrcnt;
2891
2890
Lines 2900-2906 Link Here
2900
  *rdata_len = desc.usedlen;
2899
  *rdata_len = desc.usedlen;
2901
2900
2902
  *rparam_len = 8;
2901
  *rparam_len = 8;
2903
  *rparam = REALLOC(*rparam,*rparam_len);
2902
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
2904
  SSVALS(*rparam,0,desc.errcode);
2903
  SSVALS(*rparam,0,desc.errcode);
2905
  SSVAL(*rparam,2,0);
2904
  SSVAL(*rparam,2,0);
2906
  SSVAL(*rparam,4,succnt);
2905
  SSVAL(*rparam,4,succnt);
Lines 3001-3007 Link Here
3001
  }
3000
  }
3002
  else {
3001
  else {
3003
    if (mdrcnt > 0) {
3002
    if (mdrcnt > 0) {
3004
      *rdata = REALLOC(*rdata,mdrcnt);
3003
      *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
3005
      desc.base = *rdata;
3004
      desc.base = *rdata;
3006
      desc.buflen = mdrcnt;
3005
      desc.buflen = mdrcnt;
3007
    } else {
3006
    } else {
Lines 3010-3016 Link Here
3010
       *  init_package will return wrong size if buflen=0
3009
       *  init_package will return wrong size if buflen=0
3011
       */
3010
       */
3012
      desc.buflen = getlen(desc.format);
3011
      desc.buflen = getlen(desc.format);
3013
      desc.base = tmpdata = (char *)malloc ( desc.buflen );
3012
      desc.base = tmpdata = (char *)SMB_MALLOC ( desc.buflen );
3014
    }
3013
    }
3015
    if (init_package(&desc,1,0)) {
3014
    if (init_package(&desc,1,0)) {
3016
      fill_printdest_info(conn,snum,uLevel,&desc);
3015
      fill_printdest_info(conn,snum,uLevel,&desc);
Lines 3019-3025 Link Here
3019
  }
3018
  }
3020
3019
3021
  *rparam_len = 6;
3020
  *rparam_len = 6;
3022
  *rparam = REALLOC(*rparam,*rparam_len);
3021
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
3023
  SSVALS(*rparam,0,desc.errcode);
3022
  SSVALS(*rparam,0,desc.errcode);
3024
  SSVAL(*rparam,2,0);
3023
  SSVAL(*rparam,2,0);
3025
  SSVAL(*rparam,4,desc.neededlen);
3024
  SSVAL(*rparam,4,desc.neededlen);
Lines 3058-3064 Link Here
3058
    if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i))
3057
    if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i))
3059
      queuecnt++;
3058
      queuecnt++;
3060
3059
3061
  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
3060
  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
3062
  desc.base = *rdata;
3061
  desc.base = *rdata;
3063
  desc.buflen = mdrcnt;
3062
  desc.buflen = mdrcnt;
3064
  if (init_package(&desc,queuecnt,0)) {    
3063
  if (init_package(&desc,queuecnt,0)) {    
Lines 3076-3082 Link Here
3076
  *rdata_len = desc.usedlen;
3075
  *rdata_len = desc.usedlen;
3077
3076
3078
  *rparam_len = 8;
3077
  *rparam_len = 8;
3079
  *rparam = REALLOC(*rparam,*rparam_len);
3078
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
3080
  SSVALS(*rparam,0,desc.errcode);
3079
  SSVALS(*rparam,0,desc.errcode);
3081
  SSVAL(*rparam,2,0);
3080
  SSVAL(*rparam,2,0);
3082
  SSVAL(*rparam,4,succnt);
3081
  SSVAL(*rparam,4,succnt);
Lines 3108-3114 Link Here
3108
  if (strcmp(str1,"WrLeh") != 0) return False;
3107
  if (strcmp(str1,"WrLeh") != 0) return False;
3109
  if (uLevel != 0 || strcmp(str2,"B41") != 0) return False;
3108
  if (uLevel != 0 || strcmp(str2,"B41") != 0) return False;
3110
3109
3111
  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
3110
  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
3112
  desc.base = *rdata;
3111
  desc.base = *rdata;
3113
  desc.buflen = mdrcnt;
3112
  desc.buflen = mdrcnt;
3114
  if (init_package(&desc,1,0)) {
3113
  if (init_package(&desc,1,0)) {
Lines 3120-3126 Link Here
3120
  *rdata_len = desc.usedlen;
3119
  *rdata_len = desc.usedlen;
3121
3120
3122
  *rparam_len = 8;
3121
  *rparam_len = 8;
3123
  *rparam = REALLOC(*rparam,*rparam_len);
3122
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
3124
  SSVALS(*rparam,0,desc.errcode);
3123
  SSVALS(*rparam,0,desc.errcode);
3125
  SSVAL(*rparam,2,0);
3124
  SSVAL(*rparam,2,0);
3126
  SSVAL(*rparam,4,succnt);
3125
  SSVAL(*rparam,4,succnt);
Lines 3152-3158 Link Here
3152
  if (strcmp(str1,"WrLeh") != 0) return False;
3151
  if (strcmp(str1,"WrLeh") != 0) return False;
3153
  if (uLevel != 0 || strcmp(str2,"B13") != 0) return False;
3152
  if (uLevel != 0 || strcmp(str2,"B13") != 0) return False;
3154
3153
3155
  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
3154
  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
3156
  desc.base = *rdata;
3155
  desc.base = *rdata;
3157
  desc.buflen = mdrcnt;
3156
  desc.buflen = mdrcnt;
3158
  desc.format = str2;
3157
  desc.format = str2;
Lines 3165-3171 Link Here
3165
  *rdata_len = desc.usedlen;
3164
  *rdata_len = desc.usedlen;
3166
3165
3167
  *rparam_len = 8;
3166
  *rparam_len = 8;
3168
  *rparam = REALLOC(*rparam,*rparam_len);
3167
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
3169
  SSVALS(*rparam,0,desc.errcode);
3168
  SSVALS(*rparam,0,desc.errcode);
3170
  SSVAL(*rparam,2,0);
3169
  SSVAL(*rparam,2,0);
3171
  SSVAL(*rparam,4,succnt);
3170
  SSVAL(*rparam,4,succnt);
Lines 3197-3203 Link Here
3197
  if (strcmp(str1,"WrLeh") != 0) return False;
3196
  if (strcmp(str1,"WrLeh") != 0) return False;
3198
  if (uLevel != 0 || strcmp(str2,"B9") != 0) return False;
3197
  if (uLevel != 0 || strcmp(str2,"B9") != 0) return False;
3199
3198
3200
  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
3199
  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
3201
  memset((char *)&desc,'\0',sizeof(desc));
3200
  memset((char *)&desc,'\0',sizeof(desc));
3202
  desc.base = *rdata;
3201
  desc.base = *rdata;
3203
  desc.buflen = mdrcnt;
3202
  desc.buflen = mdrcnt;
Lines 3211-3217 Link Here
3211
  *rdata_len = desc.usedlen;
3210
  *rdata_len = desc.usedlen;
3212
3211
3213
  *rparam_len = 8;
3212
  *rparam_len = 8;
3214
  *rparam = REALLOC(*rparam,*rparam_len);
3213
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
3215
  SSVALS(*rparam,0,desc.errcode);
3214
  SSVALS(*rparam,0,desc.errcode);
3216
  SSVAL(*rparam,2,0);
3215
  SSVAL(*rparam,2,0);
3217
  SSVAL(*rparam,4,succnt);
3216
  SSVAL(*rparam,4,succnt);
Lines 3231-3237 Link Here
3231
			 int *rdata_len,int *rparam_len)
3230
			 int *rdata_len,int *rparam_len)
3232
{
3231
{
3233
  *rparam_len = MIN(*rparam_len,mprcnt);
3232
  *rparam_len = MIN(*rparam_len,mprcnt);
3234
  *rparam = REALLOC(*rparam,*rparam_len);
3233
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
3235
3234
3236
  *rdata_len = 0;
3235
  *rdata_len = 0;
3237
3236
Lines 3253-3259 Link Here
3253
			    int *rdata_len,int *rparam_len)
3252
			    int *rdata_len,int *rparam_len)
3254
{
3253
{
3255
  *rparam_len = 4;
3254
  *rparam_len = 4;
3256
  *rparam = REALLOC(*rparam,*rparam_len);
3255
  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
3257
3256
3258
  *rdata_len = 0;
3257
  *rdata_len = 0;
3259
3258
Lines 3352-3362 Link Here
3352
    }
3351
    }
3353
  }
3352
  }
3354
3353
3355
  rdata = (char *)malloc(1024);
3354
  rdata = (char *)SMB_MALLOC(1024);
3356
  if (rdata)
3355
  if (rdata)
3357
    memset(rdata,'\0',1024);
3356
    memset(rdata,'\0',1024);
3358
3357
3359
  rparam = (char *)malloc(1024);
3358
  rparam = (char *)SMB_MALLOC(1024);
3360
  if (rparam)
3359
  if (rparam)
3361
    memset(rparam,'\0',1024);
3360
    memset(rparam,'\0',1024);
3362
3361
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/mangle_hash.c (-3 / +3 lines)
Lines 589-595 Link Here
589
589
590
  /* Allocate a new cache entry.  If the allocation fails, just return. */
590
  /* Allocate a new cache entry.  If the allocation fails, just return. */
591
  i = sizeof( ubi_cacheEntry ) + mangled_len + raw_len + 2;
591
  i = sizeof( ubi_cacheEntry ) + mangled_len + raw_len + 2;
592
  new_entry = malloc( i );
592
  new_entry = SMB_MALLOC( i );
593
  if( !new_entry )
593
  if( !new_entry )
594
    return;
594
    return;
595
595
Lines 635-641 Link Here
635
    ext_start = strrchr( s, '.' );
635
    ext_start = strrchr( s, '.' );
636
    if( ext_start )
636
    if( ext_start )
637
    {
637
    {
638
      if((saved_ext = strdup(ext_start)) == NULL)
638
      if((saved_ext = SMB_STRDUP(ext_start)) == NULL)
639
        return False;
639
        return False;
640
640
641
      *ext_start = '\0';
641
      *ext_start = '\0';
Lines 847-853 Link Here
847
847
848
		/* mangle it into 8.3 */
848
		/* mangle it into 8.3 */
849
		if (cache83)
849
		if (cache83)
850
			tmp = strdup(OutName);
850
			tmp = SMB_STRDUP(OutName);
851
851
852
		mangle_name_83(OutName);
852
		mangle_name_83(OutName);
853
853
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/mangle_hash2.c (-4 / +4 lines)
Lines 141-150 Link Here
141
{
141
{
142
	if (prefix_cache) return True;
142
	if (prefix_cache) return True;
143
143
144
	prefix_cache = calloc(MANGLE_CACHE_SIZE, sizeof(char *));
144
	prefix_cache = SMB_CALLOC_ARRAY(char *, MANGLE_CACHE_SIZE);
145
	if (!prefix_cache) return False;
145
	if (!prefix_cache) return False;
146
146
147
	prefix_cache_hashes = calloc(MANGLE_CACHE_SIZE, sizeof(u32));
147
	prefix_cache_hashes = SMB_CALLOC_ARRAY(u32, MANGLE_CACHE_SIZE);
148
	if (!prefix_cache_hashes) return False;
148
	if (!prefix_cache_hashes) return False;
149
149
150
	return True;
150
	return True;
Lines 161-167 Link Here
161
		free(prefix_cache[i]);
161
		free(prefix_cache[i]);
162
	}
162
	}
163
163
164
	prefix_cache[i] = strndup(prefix, length);
164
	prefix_cache[i] = SMB_STRNDUP(prefix, length);
165
	prefix_cache_hashes[i] = hash;
165
	prefix_cache_hashes[i] = hash;
166
}
166
}
167
167
Lines 252-258 Link Here
252
	DEBUG(10,("is_mangled %s ?\n", name));
252
	DEBUG(10,("is_mangled %s ?\n", name));
253
253
254
	for (s=name; (p=strchr(s, '/')); s=p+1) {
254
	for (s=name; (p=strchr(s, '/')); s=p+1) {
255
		char *component = strndup(s, PTR_DIFF(p, s));
255
		char *component = SMB_STRNDUP(s, PTR_DIFF(p, s));
256
		if (is_mangled_component(component)) {
256
		if (is_mangled_component(component)) {
257
			free(component);
257
			free(component);
258
			return True;
258
			return True;
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/notify.c (-1 / +1 lines)
Lines 178-184 Link Here
178
{
178
{
179
	struct change_notify *cnbp;
179
	struct change_notify *cnbp;
180
180
181
	if((cnbp = (struct change_notify *)malloc(sizeof(*cnbp))) == NULL) {
181
	if((cnbp = SMB_MALLOC_P(struct change_notify)) == NULL) {
182
		DEBUG(0,("call_nt_transact_notify_change: malloc fail !\n" ));
182
		DEBUG(0,("call_nt_transact_notify_change: malloc fail !\n" ));
183
		return -1;
183
		return -1;
184
	}
184
	}
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/nttrans.c (-7 / +7 lines)
Lines 1034-1040 Link Here
1034
		return ret;
1034
		return ret;
1035
1035
1036
	/* Realloc the size of parameters and data we will return */
1036
	/* Realloc the size of parameters and data we will return */
1037
	params = Realloc(*ppparams, 69);
1037
	params = SMB_REALLOC(*ppparams, 69);
1038
	if(params == NULL)
1038
	if(params == NULL)
1039
		return ERROR_DOS(ERRDOS,ERRnomem);
1039
		return ERROR_DOS(ERRDOS,ERRnomem);
1040
1040
Lines 1445-1451 Link Here
1445
	}
1445
	}
1446
1446
1447
	/* Realloc the size of parameters and data we will return */
1447
	/* Realloc the size of parameters and data we will return */
1448
	params = Realloc(*ppparams, 69);
1448
	params = SMB_REALLOC(*ppparams, 69);
1449
	if(params == NULL)
1449
	if(params == NULL)
1450
		return ERROR_DOS(ERRDOS,ERRnomem);
1450
		return ERROR_DOS(ERRDOS,ERRnomem);
1451
1451
Lines 1659-1665 Link Here
1659
1659
1660
  DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp->fsp_name ));
1660
  DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp->fsp_name ));
1661
1661
1662
  params = Realloc(*ppparams, 4);
1662
  params = SMB_REALLOC(*ppparams, 4);
1663
  if(params == NULL)
1663
  if(params == NULL)
1664
    return ERROR_DOS(ERRDOS,ERRnomem);
1664
    return ERROR_DOS(ERRDOS,ERRnomem);
1665
1665
Lines 1700-1706 Link Here
1700
   * Allocate the data we will point this at.
1700
   * Allocate the data we will point this at.
1701
   */
1701
   */
1702
1702
1703
  data = Realloc(*ppdata, sd_size);
1703
  data = SMB_REALLOC(*ppdata, sd_size);
1704
  if(data == NULL) {
1704
  if(data == NULL) {
1705
    talloc_destroy(mem_ctx);
1705
    talloc_destroy(mem_ctx);
1706
    return ERROR_DOS(ERRDOS,ERRnomem);
1706
    return ERROR_DOS(ERRDOS,ERRnomem);
Lines 1896-1906 Link Here
1896
	/* Allocate the space for the setup, the maximum needed parameters and data */
1896
	/* Allocate the space for the setup, the maximum needed parameters and data */
1897
1897
1898
	if(setup_count > 0)
1898
	if(setup_count > 0)
1899
		setup = (char *)malloc(setup_count);
1899
		setup = (char *)SMB_MALLOC(setup_count);
1900
	if (total_parameter_count > 0)
1900
	if (total_parameter_count > 0)
1901
		params = (char *)malloc(total_parameter_count);
1901
		params = (char *)SMB_MALLOC(total_parameter_count);
1902
	if (total_data_count > 0)
1902
	if (total_data_count > 0)
1903
		data = (char *)malloc(total_data_count);
1903
		data = (char *)SMB_MALLOC(total_data_count);
1904
 
1904
 
1905
	if ((total_parameter_count && !params)  || (total_data_count && !data) ||
1905
	if ((total_parameter_count && !params)  || (total_data_count && !data) ||
1906
				(setup_count && !setup)) {
1906
				(setup_count && !setup)) {
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/oplock.c (-2 / +2 lines)
Lines 709-720 Link Here
709
	 * messages crossing on the wire.
709
	 * messages crossing on the wire.
710
	 */
710
	 */
711
711
712
	if((inbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
712
	if((inbuf = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
713
		DEBUG(0,("oplock_break: malloc fail for input buffer.\n"));
713
		DEBUG(0,("oplock_break: malloc fail for input buffer.\n"));
714
		return False;
714
		return False;
715
	}
715
	}
716
716
717
	if((outbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
717
	if((outbuf = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
718
		DEBUG(0,("oplock_break: malloc fail for output buffer.\n"));
718
		DEBUG(0,("oplock_break: malloc fail for output buffer.\n"));
719
		SAFE_FREE(inbuf);
719
		SAFE_FREE(inbuf);
720
		return False;
720
		return False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/password.c (-8 / +8 lines)
Lines 184-190 Link Here
184
	size_t num_sids = 0;
184
	size_t num_sids = 0;
185
	fstring sid_str;
185
	fstring sid_str;
186
186
187
	if ((token = (NT_USER_TOKEN *)malloc( sizeof(NT_USER_TOKEN) ) ) == NULL)
187
	if ((token = SMB_MALLOC_P(NT_USER_TOKEN ) ) == NULL)
188
		return NULL;
188
		return NULL;
189
189
190
	ZERO_STRUCTP(token);
190
	ZERO_STRUCTP(token);
Lines 195-201 Link Here
195
	if (sup_tok && sup_tok->num_sids)
195
	if (sup_tok && sup_tok->num_sids)
196
		num_sids += sup_tok->num_sids;
196
		num_sids += sup_tok->num_sids;
197
197
198
	if ((token->user_sids = (DOM_SID *)malloc( num_sids*sizeof(DOM_SID))) == NULL) {
198
	if ((token->user_sids = SMB_MALLOC_ARRAY( DOM_SID, num_sids)) == NULL) {
199
		SAFE_FREE(token);
199
		SAFE_FREE(token);
200
		return NULL;
200
		return NULL;
201
	}
201
	}
Lines 277-283 Link Here
277
	if (num_validated_vuids >= 0xFFFF-VUID_OFFSET)
277
	if (num_validated_vuids >= 0xFFFF-VUID_OFFSET)
278
		return UID_FIELD_INVALID;
278
		return UID_FIELD_INVALID;
279
279
280
	if((vuser = (user_struct *)malloc( sizeof(user_struct) )) == NULL) {
280
	if((vuser = SMB_MALLOC_P(user_struct)) == NULL) {
281
		DEBUG(0,("Failed to malloc users struct!\n"));
281
		DEBUG(0,("Failed to malloc users struct!\n"));
282
		return UID_FIELD_INVALID;
282
		return UID_FIELD_INVALID;
283
	}
283
	}
Lines 773-779 Link Here
773
		/* now check the list of session users */
773
		/* now check the list of session users */
774
		if (!ok) {
774
		if (!ok) {
775
			char *auser;
775
			char *auser;
776
			char *user_list = strdup(session_users);
776
			char *user_list = SMB_STRDUP(session_users);
777
			if (!user_list)
777
			if (!user_list)
778
				return(False);
778
				return(False);
779
779
Lines 1025-1031 Link Here
1025
	if (!cli_initialise(cli))
1025
	if (!cli_initialise(cli))
1026
		return NULL;
1026
		return NULL;
1027
1027
1028
	pserver = strdup(lp_passwordserver());
1028
	pserver = SMB_STRDUP(lp_passwordserver());
1029
	p = pserver;
1029
	p = pserver;
1030
1030
1031
	while(next_token( &p, desthost, LIST_SEP, sizeof(desthost))) {
1031
	while(next_token( &p, desthost, LIST_SEP, sizeof(desthost))) {
Lines 1193-1199 Link Here
1193
1193
1194
static BOOL grab_server_mutex(const char *name)
1194
static BOOL grab_server_mutex(const char *name)
1195
{
1195
{
1196
	mutex_server_name = strdup(name);
1196
	mutex_server_name = SMB_STRDUP(name);
1197
	if (!mutex_server_name) {
1197
	if (!mutex_server_name) {
1198
		DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name));
1198
		DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name));
1199
		return False;
1199
		return False;
Lines 1645-1658 Link Here
1645
 
1645
 
1646
		*pptoken = NULL;
1646
		*pptoken = NULL;
1647
 
1647
 
1648
		if ((ptok = (NT_USER_TOKEN *)malloc( sizeof(NT_USER_TOKEN) ) ) == NULL) {
1648
		if ((ptok = SMB_MALLOC_P(NT_USER_TOKEN) ) == NULL) {
1649
			DEBUG(0, ("domain_client_validate: Out of memory allocating NT_USER_TOKEN\n"));
1649
			DEBUG(0, ("domain_client_validate: Out of memory allocating NT_USER_TOKEN\n"));
1650
			release_server_mutex();
1650
			release_server_mutex();
1651
			return False;
1651
			return False;
1652
		}
1652
		}
1653
 
1653
 
1654
		ptok->num_sids = (size_t)info3.num_groups2 + info3.num_other_sids;
1654
		ptok->num_sids = (size_t)info3.num_groups2 + info3.num_other_sids;
1655
		if ((ptok->user_sids = (DOM_SID *)malloc( sizeof(DOM_SID) * ptok->num_sids )) == NULL) {
1655
		if ((ptok->user_sids = SMB_MALLOC_ARRAY( DOM_SID, ptok->num_sids )) == NULL) {
1656
			DEBUG(0, ("domain_client_validate: Out of memory allocating group SIDS\n"));
1656
			DEBUG(0, ("domain_client_validate: Out of memory allocating group SIDS\n"));
1657
			SAFE_FREE(ptok);
1657
			SAFE_FREE(ptok);
1658
			release_server_mutex();
1658
			release_server_mutex();
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/posix_acls.c (-7 / +7 lines)
Lines 84-90 Link Here
84
84
85
static canon_ace *dup_canon_ace( canon_ace *src_ace)
85
static canon_ace *dup_canon_ace( canon_ace *src_ace)
86
{
86
{
87
	canon_ace *dst_ace = (canon_ace *)malloc(sizeof(canon_ace));
87
	canon_ace *dst_ace = SMB_MALLOC_P(canon_ace);
88
88
89
	if (dst_ace == NULL)
89
	if (dst_ace == NULL)
90
		return NULL;
90
		return NULL;
Lines 703-709 Link Here
703
	}
703
	}
704
704
705
	if (!got_user) {
705
	if (!got_user) {
706
		if ((pace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
706
		if ((pace = SMB_MALLOC_P(canon_ace)) == NULL) {
707
			DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
707
			DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
708
			return False;
708
			return False;
709
		}
709
		}
Lines 738-744 Link Here
738
	}
738
	}
739
739
740
	if (!got_grp) {
740
	if (!got_grp) {
741
		if ((pace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
741
		if ((pace = SMB_MALLOC_P(canon_ace)) == NULL) {
742
			DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
742
			DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
743
			return False;
743
			return False;
744
		}
744
		}
Lines 768-774 Link Here
768
	}
768
	}
769
769
770
	if (!got_other) {
770
	if (!got_other) {
771
		if ((pace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
771
		if ((pace = SMB_MALLOC_P(canon_ace)) == NULL) {
772
			DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
772
			DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
773
			return False;
773
			return False;
774
		}
774
		}
Lines 956-962 Link Here
956
		 * Create a cannon_ace entry representing this NT DACL ACE.
956
		 * Create a cannon_ace entry representing this NT DACL ACE.
957
		 */
957
		 */
958
958
959
		if ((current_ace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
959
		if ((current_ace = SMB_MALLOC_P(canon_ace)) == NULL) {
960
			free_canon_ace_list(file_ace);
960
			free_canon_ace_list(file_ace);
961
			free_canon_ace_list(dir_ace);
961
			free_canon_ace_list(dir_ace);
962
			DEBUG(0,("create_canon_ace_lists: malloc fail.\n"));
962
			DEBUG(0,("create_canon_ace_lists: malloc fail.\n"));
Lines 1743-1749 Link Here
1743
		 * Add this entry to the list.
1743
		 * Add this entry to the list.
1744
		 */
1744
		 */
1745
1745
1746
		if ((ace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL)
1746
		if ((ace = SMB_MALLOC_P(canon_ace)) == NULL)
1747
			goto fail;
1747
			goto fail;
1748
1748
1749
		ZERO_STRUCTP(ace);
1749
		ZERO_STRUCTP(ace);
Lines 2387-2393 Link Here
2387
		num_dir_acls = count_canon_ace_list(dir_ace);
2387
		num_dir_acls = count_canon_ace_list(dir_ace);
2388
2388
2389
		/* Allocate the ace list. */
2389
		/* Allocate the ace list. */
2390
		if ((nt_ace_list = (SEC_ACE *)malloc((num_acls + num_profile_acls + num_dir_acls)* sizeof(SEC_ACE))) == NULL) {
2390
		if ((nt_ace_list = SMB_MALLOC_ARRAY(SEC_ACE, num_acls + num_profile_acls + num_dir_acls)) == NULL) {
2391
			DEBUG(0,("get_nt_acl: Unable to malloc space for nt_ace_list.\n"));
2391
			DEBUG(0,("get_nt_acl: Unable to malloc space for nt_ace_list.\n"));
2392
			goto done;
2392
			goto done;
2393
		}
2393
		}
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/process.c (-5 / +4 lines)
Lines 73-80 Link Here
73
73
74
static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len)
74
static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len)
75
{
75
{
76
  pending_message_list *msg = (pending_message_list *)
76
  pending_message_list *msg = SMB_MALLOC_P(pending_message_list);
77
                               malloc(sizeof(pending_message_list));
78
77
79
  if(msg == NULL)
78
  if(msg == NULL)
80
  {
79
  {
Lines 82-88 Link Here
82
    return False;
81
    return False;
83
  }
82
  }
84
83
85
  msg->msg_buf = (char *)malloc(msg_len);
84
  msg->msg_buf = (char *)SMB_MALLOC(msg_len);
86
  if(msg->msg_buf == NULL)
85
  if(msg->msg_buf == NULL)
87
  {
86
  {
88
    DEBUG(0,("push_message: malloc fail (2)\n"));
87
    DEBUG(0,("push_message: malloc fail (2)\n"));
Lines 1212-1219 Link Here
1212
	time_t last_timeout_processing_time = time(NULL);
1211
	time_t last_timeout_processing_time = time(NULL);
1213
	unsigned int num_smbs = 0;
1212
	unsigned int num_smbs = 0;
1214
1213
1215
	InBuffer = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN);
1214
	InBuffer = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN);
1216
	OutBuffer = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN);
1215
	OutBuffer = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN);
1217
	if ((InBuffer == NULL) || (OutBuffer == NULL)) 
1216
	if ((InBuffer == NULL) || (OutBuffer == NULL)) 
1218
		return;
1217
		return;
1219
1218
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/reply.c (-2 / +2 lines)
Lines 1470-1476 Link Here
1470
		END_PROFILE(SMBsearch);
1470
		END_PROFILE(SMBsearch);
1471
        return ERROR_DOS(ERRDOS,ERRnofids);
1471
        return ERROR_DOS(ERRDOS,ERRnofids);
1472
      }
1472
      }
1473
      dptr_set_wcard(dptr_num, strdup(mask));
1473
      dptr_set_wcard(dptr_num, SMB_STRDUP(mask));
1474
      dptr_set_attr(dptr_num, dirtype);
1474
      dptr_set_attr(dptr_num, dirtype);
1475
    } else {
1475
    } else {
1476
      dirtype = dptr_attr(dptr_num);
1476
      dirtype = dptr_attr(dptr_num);
Lines 4990-4996 Link Here
4990
		if(fsp->wbmpx_ptr != NULL)
4990
		if(fsp->wbmpx_ptr != NULL)
4991
			wbms = fsp->wbmpx_ptr; /* Use an existing struct */
4991
			wbms = fsp->wbmpx_ptr; /* Use an existing struct */
4992
		else
4992
		else
4993
			wbms = (write_bmpx_struct *)malloc(sizeof(write_bmpx_struct));
4993
			wbms = SMB_MALLOC_P(write_bmpx_struct);
4994
4994
4995
		if(!wbms) {
4995
		if(!wbms) {
4996
			DEBUG(0,("Out of memory in reply_readmpx\n"));
4996
			DEBUG(0,("Out of memory in reply_readmpx\n"));
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/sec_ctx.c (-3 / +3 lines)
Lines 155-161 Link Here
155
		goto fail;
155
		goto fail;
156
	}
156
	}
157
157
158
	if((groups = (gid_t *)malloc(sizeof(gid_t)*(ngroups+1))) == NULL) {
158
	if((groups = SMB_MALLOC_ARRAY(gid_t, ngroups+1)) == NULL) {
159
		DEBUG(0,("setup_groups malloc fail !\n"));
159
		DEBUG(0,("setup_groups malloc fail !\n"));
160
		goto fail;
160
		goto fail;
161
	}
161
	}
Lines 208-214 Link Here
208
	if (!ptoken)
208
	if (!ptoken)
209
		return NULL;
209
		return NULL;
210
210
211
    if ((token = (NT_USER_TOKEN *)malloc( sizeof(NT_USER_TOKEN) ) ) == NULL)
211
    if ((token = SMB_MALLOC_P(NT_USER_TOKEN) ) == NULL)
212
        return NULL;
212
        return NULL;
213
213
214
    ZERO_STRUCTP(token);
214
    ZERO_STRUCTP(token);
Lines 301-307 Link Here
301
	ctx_p->ngroups = sys_getgroups(0, NULL);
301
	ctx_p->ngroups = sys_getgroups(0, NULL);
302
302
303
	if (ctx_p->ngroups != 0) {
303
	if (ctx_p->ngroups != 0) {
304
		if (!(ctx_p->groups = malloc(ctx_p->ngroups * sizeof(gid_t)))) {
304
		if (!(ctx_p->groups = SMB_MALLOC_ARRAY(gid_t, ctx_p->ngroups))) {
305
			DEBUG(0, ("Out of memory in push_sec_ctx()\n"));
305
			DEBUG(0, ("Out of memory in push_sec_ctx()\n"));
306
			delete_nt_token(&ctx_p->token);
306
			delete_nt_token(&ctx_p->token);
307
			return False;
307
			return False;
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/statcache.c (-2 / +2 lines)
Lines 103-109 Link Here
103
      return;
103
      return;
104
    } else {
104
    } else {
105
      hash_remove(&stat_cache, hash_elem);
105
      hash_remove(&stat_cache, hash_elem);
106
      if((scp = (stat_cache_entry *)malloc(sizeof(stat_cache_entry)+2*namelen)) == NULL) {
106
      if((scp = (stat_cache_entry *)SMB_MALLOC(sizeof(stat_cache_entry)+2*namelen)) == NULL) {
107
        DEBUG(0,("stat_cache_add: Out of memory !\n"));
107
        DEBUG(0,("stat_cache_add: Out of memory !\n"));
108
        return;
108
        return;
109
      }
109
      }
Lines 119-125 Link Here
119
     * New entry.
119
     * New entry.
120
     */
120
     */
121
121
122
    if((scp = (stat_cache_entry *)malloc(sizeof(stat_cache_entry)+2*namelen)) == NULL) {
122
    if((scp = (stat_cache_entry *)SMB_MALLOC(sizeof(stat_cache_entry)+2*namelen)) == NULL) {
123
      DEBUG(0,("stat_cache_add: Out of memory !\n"));
123
      DEBUG(0,("stat_cache_add: Out of memory !\n"));
124
      return;
124
      return;
125
    }
125
    }
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/trans2.c (-16 / +16 lines)
Lines 305-311 Link Here
305
	}
305
	}
306
306
307
	/* Realloc the size of parameters and data we will return */
307
	/* Realloc the size of parameters and data we will return */
308
	params = Realloc(*pparams, 28);
308
	params = SMB_REALLOC(*pparams, 28);
309
	if( params == NULL )
309
	if( params == NULL )
310
		return(ERROR_DOS(ERRDOS,ERRnomem));
310
		return(ERROR_DOS(ERRDOS,ERRnomem));
311
	*pparams = params;
311
	*pparams = params;
Lines 970-983 Link Here
970
970
971
	DEBUG(5,("dir=%s, mask = %s\n",directory, mask));
971
	DEBUG(5,("dir=%s, mask = %s\n",directory, mask));
972
972
973
	pdata = Realloc(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
973
	pdata = SMB_REALLOC(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
974
	if( pdata == NULL )
974
	if( pdata == NULL )
975
		return(ERROR_DOS(ERRDOS,ERRnomem));
975
		return(ERROR_DOS(ERRDOS,ERRnomem));
976
	*ppdata = pdata;
976
	*ppdata = pdata;
977
	memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
977
	memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
978
978
979
	/* Realloc the params space */
979
	/* Realloc the params space */
980
	params = Realloc(*pparams, 10);
980
	params = SMB_REALLOC(*pparams, 10);
981
	if( params == NULL )
981
	if( params == NULL )
982
		return ERROR_DOS(ERRDOS,ERRnomem);
982
		return ERROR_DOS(ERRDOS,ERRnomem);
983
	*pparams = params;
983
	*pparams = params;
Lines 989-995 Link Here
989
	/* Save the wildcard match and attribs we are using on this directory - 
989
	/* Save the wildcard match and attribs we are using on this directory - 
990
		needed as lanman2 assumes these are being saved between calls */
990
		needed as lanman2 assumes these are being saved between calls */
991
991
992
	if(!(wcard = strdup(mask))) {
992
	if(!(wcard = SMB_STRDUP(mask))) {
993
		dptr_close(&dptr_num);
993
		dptr_close(&dptr_num);
994
		return ERROR_DOS(ERRDOS,ERRnomem);
994
		return ERROR_DOS(ERRDOS,ERRnomem);
995
	}
995
	}
Lines 1170-1176 Link Here
1170
			return ERROR_DOS(ERRDOS,ERRunknownlevel);
1170
			return ERROR_DOS(ERRDOS,ERRunknownlevel);
1171
	}
1171
	}
1172
1172
1173
	pdata = Realloc( *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
1173
	pdata = SMB_REALLOC( *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
1174
	if(pdata == NULL)
1174
	if(pdata == NULL)
1175
		return ERROR_DOS(ERRDOS,ERRnomem);
1175
		return ERROR_DOS(ERRDOS,ERRnomem);
1176
1176
Lines 1178-1184 Link Here
1178
	memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
1178
	memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
1179
1179
1180
	/* Realloc the params space */
1180
	/* Realloc the params space */
1181
	params = Realloc(*pparams, 6*SIZEOFWORD);
1181
	params = SMB_REALLOC(*pparams, 6*SIZEOFWORD);
1182
	if( params == NULL )
1182
	if( params == NULL )
1183
		return ERROR_DOS(ERRDOS,ERRnomem);
1183
		return ERROR_DOS(ERRDOS,ERRnomem);
1184
	*pparams = params;
1184
	*pparams = params;
Lines 1377-1383 Link Here
1377
		return ERROR_DOS(ERRSRV,ERRinvdevice);
1377
		return ERROR_DOS(ERRSRV,ERRinvdevice);
1378
	}
1378
	}
1379
1379
1380
	pdata = Realloc(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
1380
	pdata = SMB_REALLOC(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
1381
	if ( pdata == NULL )
1381
	if ( pdata == NULL )
1382
		return ERROR_DOS(ERRDOS,ERRnomem);
1382
		return ERROR_DOS(ERRDOS,ERRnomem);
1383
1383
Lines 1766-1778 Link Here
1766
	/* from now on we only want the part after the / */
1766
	/* from now on we only want the part after the / */
1767
	fname = p;
1767
	fname = p;
1768
  
1768
  
1769
	params = Realloc(*pparams,2);
1769
	params = SMB_REALLOC(*pparams,2);
1770
	if ( params == NULL )
1770
	if ( params == NULL )
1771
	  return ERROR_DOS(ERRDOS,ERRnomem);
1771
	  return ERROR_DOS(ERRDOS,ERRnomem);
1772
	*pparams	= params;
1772
	*pparams	= params;
1773
	memset((char *)params,'\0',2);
1773
	memset((char *)params,'\0',2);
1774
	data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
1774
	data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
1775
	pdata = Realloc(*ppdata, data_size); 
1775
	pdata = SMB_REALLOC(*ppdata, data_size); 
1776
	if ( pdata == NULL )
1776
	if ( pdata == NULL )
1777
		return ERROR_DOS(ERRDOS,ERRnomem);
1777
		return ERROR_DOS(ERRDOS,ERRnomem);
1778
	*ppdata	= pdata;
1778
	*ppdata	= pdata;
Lines 2415-2421 Link Here
2415
		tran_call,fname,info_level,total_data));
2415
		tran_call,fname,info_level,total_data));
2416
2416
2417
	/* Realloc the parameter and data sizes */
2417
	/* Realloc the parameter and data sizes */
2418
	params = Realloc(*pparams,2);
2418
	params = SMB_REALLOC(*pparams,2);
2419
	if(params == NULL)
2419
	if(params == NULL)
2420
		return ERROR_DOS(ERRDOS,ERRnomem);
2420
		return ERROR_DOS(ERRDOS,ERRnomem);
2421
	*pparams = params;
2421
	*pparams = params;
Lines 2969-2975 Link Here
2969
	}
2969
	}
2970
2970
2971
	/* Realloc the parameter and data sizes */
2971
	/* Realloc the parameter and data sizes */
2972
	params = Realloc(*pparams,2);
2972
	params = SMB_REALLOC(*pparams,2);
2973
	if(params == NULL)
2973
	if(params == NULL)
2974
		return ERROR_DOS(ERRDOS,ERRnomem);
2974
		return ERROR_DOS(ERRDOS,ERRnomem);
2975
	*pparams = params;
2975
	*pparams = params;
Lines 3008-3014 Link Here
3008
	}
3008
	}
3009
3009
3010
	/* Realloc the parameter and data sizes */
3010
	/* Realloc the parameter and data sizes */
3011
	params = Realloc(*pparams,6);
3011
	params = SMB_REALLOC(*pparams,6);
3012
	if(params == NULL)
3012
	if(params == NULL)
3013
		return ERROR_DOS(ERRDOS,ERRnomem);
3013
		return ERROR_DOS(ERRDOS,ERRnomem);
3014
	*pparams = params;
3014
	*pparams = params;
Lines 3040-3046 Link Here
3040
	DEBUG(3,("call_trans2findnotifynext\n"));
3040
	DEBUG(3,("call_trans2findnotifynext\n"));
3041
3041
3042
	/* Realloc the parameter and data sizes */
3042
	/* Realloc the parameter and data sizes */
3043
	params = Realloc(*pparams,4);
3043
	params = SMB_REALLOC(*pparams,4);
3044
	if(params == NULL)
3044
	if(params == NULL)
3045
		return ERROR_DOS(ERRDOS,ERRnomem);
3045
		return ERROR_DOS(ERRDOS,ERRnomem);
3046
	*pparams = params;
3046
	*pparams = params;
Lines 3109-3115 Link Here
3109
3109
3110
	if ((SVAL(inbuf,(smb_setup+4)) == LMCAT_SPL) &&
3110
	if ((SVAL(inbuf,(smb_setup+4)) == LMCAT_SPL) &&
3111
			(SVAL(inbuf,(smb_setup+6)) == LMFUNC_GETJOBID)) {
3111
			(SVAL(inbuf,(smb_setup+6)) == LMFUNC_GETJOBID)) {
3112
		pdata = Realloc(*ppdata, 32);
3112
		pdata = SMB_REALLOC(*ppdata, 32);
3113
		if(pdata == NULL)
3113
		if(pdata == NULL)
3114
			return ERROR_DOS(ERRDOS,ERRnomem);
3114
			return ERROR_DOS(ERRDOS,ERRnomem);
3115
		*ppdata = pdata;
3115
		*ppdata = pdata;
Lines 3253-3261 Link Here
3253
    
3253
    
3254
	/* Allocate the space for the maximum needed parameters and data */
3254
	/* Allocate the space for the maximum needed parameters and data */
3255
	if (total_params > 0)
3255
	if (total_params > 0)
3256
		params = (char *)malloc(total_params);
3256
		params = (char *)SMB_MALLOC(total_params);
3257
	if (total_data > 0)
3257
	if (total_data > 0)
3258
		data = (char *)malloc(total_data);
3258
		data = (char *)SMB_MALLOC(total_data);
3259
  
3259
  
3260
	if ((total_params && !params)  || (total_data && !data)) {
3260
	if ((total_params && !params)  || (total_data && !data)) {
3261
		DEBUG(2,("Out of memory in reply_trans2\n"));
3261
		DEBUG(2,("Out of memory in reply_trans2\n"));
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/uid.c (-3 / +3 lines)
Lines 395-401 Link Here
395
395
396
	total_groups = current_n_groups + ptok->num_sids;
396
	total_groups = current_n_groups + ptok->num_sids;
397
 
397
 
398
	final_groups = (gid_t *)malloc(total_groups * sizeof(gid_t));
398
	final_groups = SMB_MALLOC_ARRAY(gid_t, total_groups );
399
	if (!final_groups) {
399
	if (!final_groups) {
400
		DEBUG(0,("add_supplementary_nt_login_groups: Failed to malloc new groups.\n"));
400
		DEBUG(0,("add_supplementary_nt_login_groups: Failed to malloc new groups.\n"));
401
		delete_nt_token(&new_tok);
401
		delete_nt_token(&new_tok);
Lines 640-646 Link Here
640
		}
640
		}
641
	}
641
	}
642
642
643
	pc = (struct uid_sid_cache *)malloc(sizeof(struct uid_sid_cache));
643
	pc = SMB_MALLOC_P(struct uid_sid_cache);
644
	if (!pc)
644
	if (!pc)
645
		return;
645
		return;
646
	pc->uid = uid;
646
	pc->uid = uid;
Lines 716-722 Link Here
716
		}
716
		}
717
	}
717
	}
718
718
719
	pc = (struct gid_sid_cache *)malloc(sizeof(struct gid_sid_cache));
719
	pc = SMB_MALLOC_P(struct gid_sid_cache);
720
	if (!pc)
720
	if (!pc)
721
		return;
721
		return;
722
	pc->gid = gid;
722
	pc->gid = gid;
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbd/vfs.c (-2 / +2 lines)
Lines 504-510 Link Here
504
504
505
    /* Create new vfs option */
505
    /* Create new vfs option */
506
506
507
    new_option = (struct vfs_options *)malloc(sizeof(*new_option));
507
    new_option = SMB_MALLOC_P(struct vfs_options);
508
    if (new_option == NULL) {
508
    if (new_option == NULL) {
509
	return False;
509
	return False;
510
    }
510
    }
Lines 601-607 Link Here
601
	if (element == 0)
601
	if (element == 0)
602
		return;
602
		return;
603
603
604
	p = (char *)malloc(elsize);
604
	p = (char *)SMB_MALLOC(elsize);
605
605
606
	if (!p) {
606
	if (!p) {
607
		DEBUG(5,("array_promote: malloc fail\n"));
607
		DEBUG(5,("array_promote: malloc fail\n"));
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbwrapper/shared.c (-2 / +2 lines)
Lines 111-117 Link Here
111
	if (fstat(shared_fd, &st)) goto failed;
111
	if (fstat(shared_fd, &st)) goto failed;
112
112
113
	if (st.st_size != shared_size) {
113
	if (st.st_size != shared_size) {
114
		variables = (char *)Realloc(variables, st.st_size);
114
		variables = (char *)SMB_REALLOC(variables, st.st_size);
115
		if (!variables) goto failed;
115
		if (!variables) goto failed;
116
		shared_size = st.st_size;
116
		shared_size = st.st_size;
117
		lseek(shared_fd, 0, SEEK_SET);
117
		lseek(shared_fd, 0, SEEK_SET);
Lines 165-171 Link Here
165
	l1 = strlen(name)+1;
165
	l1 = strlen(name)+1;
166
	l2 = strlen(val)+1;
166
	l2 = strlen(val)+1;
167
167
168
	variables = (char *)Realloc(variables, shared_size + l1+l2+4);
168
	variables = (char *)SMB_REALLOC(variables, shared_size + l1+l2+4);
169
169
170
	if (!variables) {
170
	if (!variables) {
171
		DEBUG(0,("out of memory in smbw_setshared\n"));
171
		DEBUG(0,("out of memory in smbw_setshared\n"));
(-)samba-2.2.12-pre-CAN-2004-1154/source/smbwrapper/smbw_dir.c (-3 / +1 lines)
Lines 80-88 Link Here
80
	DEBUG(5,("%s\n", finfo->name));
80
	DEBUG(5,("%s\n", finfo->name));
81
81
82
	if (cur_dir->malloced == cur_dir->count) {
82
	if (cur_dir->malloced == cur_dir->count) {
83
		cur_dir->list = (struct file_info *)Realloc(cur_dir->list, 
83
		cur_dir->list = SMB_REALLOC_ARRAY(cur_dir->list, struct file_info, cur_dir->count+100 );
84
							    sizeof(cur_dir->list[0])*
85
							    (cur_dir->count+100));
86
		if (!cur_dir->list) {
84
		if (!cur_dir->list) {
87
			/* oops */
85
			/* oops */
88
			return;
86
			return;
(-)samba-2.2.12-pre-CAN-2004-1154/source/tdb/tdb.c (+24 lines)
Lines 39-44 Link Here
39
#include "spinlock.h"
39
#include "spinlock.h"
40
#else
40
#else
41
#include "includes.h"
41
#include "includes.h"
42
43
#if defined(PARANOID_MALLOC_CHECKER)
44
#ifdef malloc
45
#undef malloc
46
#endif
47
48
#ifdef realloc
49
#undef realloc
50
#endif
51
52
#ifdef calloc
53
#undef calloc
54
#endif
55
56
#ifdef strdup
57
#undef strdup
58
#endif
59
60
#ifdef strndup
61
#undef strndup
62
#endif
63
64
#endif
65
42
#endif
66
#endif
43
67
44
#define TDB_MAGIC_FOOD "TDB file\n"
68
#define TDB_MAGIC_FOOD "TDB file\n"
(-)samba-2.2.12-pre-CAN-2004-1154/source/tdb/tdbutil.c (-1 / +1 lines)
Lines 484-490 Link Here
484
			len += *i;
484
			len += *i;
485
			if (bufsize < len)
485
			if (bufsize < len)
486
				goto no_space;
486
				goto no_space;
487
			*b = (char *)malloc(*i);
487
			*b = (char *)SMB_MALLOC(*i);
488
			if (! *b)
488
			if (! *b)
489
				goto no_space;
489
				goto no_space;
490
			memcpy(*b, buf+4, *i);
490
			memcpy(*b, buf+4, *i);
(-)samba-2.2.12-pre-CAN-2004-1154/source/utils/make_printerdef.c (-11 / +11 lines)
Lines 83-90 Link Here
83
  char *temp;
83
  char *temp;
84
  int i=0;
84
  int i=0;
85
 
85
 
86
  *entry=(char *)malloc(sizeof(pstring));
86
  *entry=(char *)SMB_MALLOC(sizeof(pstring));
87
  value=(char *)malloc(sizeof(pstring));
87
  value=(char *)SMB_MALLOC(sizeof(pstring));
88
88
89
  if(*entry == NULL || value == NULL) {
89
  if(*entry == NULL || value == NULL) {
90
    fprintf(stderr,"scan: malloc fail !\n");
90
    fprintf(stderr,"scan: malloc fail !\n");
Lines 151-158 Link Here
151
  int found=0,pointeur=0,i=0;
151
  int found=0,pointeur=0,i=0;
152
  char *temp,*temp2;
152
  char *temp,*temp2;
153
  
153
  
154
  temp=(char *)malloc(sizeof(pstring));
154
  temp=(char *)SMB_MALLOC(sizeof(pstring));
155
  temp2=(char *)malloc(sizeof(pstring));
155
  temp2=(char *)SMB_MALLOC(sizeof(pstring));
156
  
156
  
157
  if(temp == NULL || temp2 == NULL) {
157
  if(temp == NULL || temp2 == NULL) {
158
	  safe_free(temp);
158
	  safe_free(temp);
Lines 215-222 Link Here
215
  int found=0,pointeur=0,i=0;
215
  int found=0,pointeur=0,i=0;
216
  char *temp,*temp2;
216
  char *temp,*temp2;
217
  
217
  
218
  temp=(char *)malloc(sizeof(pstring));
218
  temp=(char *)SMB_MALLOC(sizeof(pstring));
219
  temp2=(char *)malloc(sizeof(pstring));
219
  temp2=(char *)SMB_MALLOC(sizeof(pstring));
220
  
220
  
221
  if(temp == NULL || temp2 == NULL) {
221
  if(temp == NULL || temp2 == NULL) {
222
	  safe_free(temp);
222
	  safe_free(temp);
Lines 273-281 Link Here
273
273
274
  int found=0;
274
  int found=0;
275
275
276
  chaine=(char *)malloc(sizeof(pstring));
276
  chaine=(char *)SMB_MALLOC(sizeof(pstring));
277
  long_desc=(char *)malloc(sizeof(pstring));
277
  long_desc=(char *)SMB_MALLOC(sizeof(pstring));
278
  short_desc=(char *)malloc(sizeof(pstring));
278
  short_desc=(char *)SMB_MALLOC(sizeof(pstring));
279
  if (!chaine || !long_desc || !short_desc) {
279
  if (!chaine || !long_desc || !short_desc) {
280
	  safe_free(chaine);
280
	  safe_free(chaine);
281
	  safe_free(long_desc);
281
	  safe_free(long_desc);
Lines 450-456 Link Here
450
  languagemonitor=0;
450
  languagemonitor=0;
451
  vendorsetup=0;
451
  vendorsetup=0;
452
  datatype="RAW";
452
  datatype="RAW";
453
  if((temp=(char *)malloc(sizeof(pstring))) == NULL) {
453
  if((temp=(char *)SMB_MALLOC(sizeof(pstring))) == NULL) {
454
    fprintf(stderr, "scan_short_desc: malloc fail !\n");
454
    fprintf(stderr, "scan_short_desc: malloc fail !\n");
455
    exit(1);
455
    exit(1);
456
  }
456
  }
Lines 572-578 Link Here
572
  lookup_entry(inf_file,"DestinationDirs");
572
  lookup_entry(inf_file,"DestinationDirs");
573
  build_subdir();
573
  build_subdir();
574
574
575
  if((files_to_copy=(char *)malloc(2048*sizeof(char))) == NULL) {
575
  if((files_to_copy=(char *)SMB_MALLOC(2048*sizeof(char))) == NULL) {
576
    fprintf(stderr, "%s: malloc fail.\n", argv[0] );
576
    fprintf(stderr, "%s: malloc fail.\n", argv[0] );
577
    exit(1);
577
    exit(1);
578
  }
578
  }
(-)samba-2.2.12-pre-CAN-2004-1154/source/utils/make_smbcodepage.c (-3 / +3 lines)
Lines 67-73 Link Here
67
  pstring linebuf;
67
  pstring linebuf;
68
  char *p = *buf;
68
  char *p = *buf;
69
  int num_lines = 0;
69
  int num_lines = 0;
70
  char *newbuf = (char *)malloc( *size + 1);
70
  char *newbuf = (char *)SMB_MALLOC( *size + 1);
71
  char *newbuf_p = NULL;
71
  char *newbuf_p = NULL;
72
72
73
  if(newbuf == NULL)
73
  if(newbuf == NULL)
Lines 198-204 Link Here
198
  }
198
  }
199
199
200
  /* As we will be reading text, allocate one more byte for a '\0' */
200
  /* As we will be reading text, allocate one more byte for a '\0' */
201
  if((buf = (char *)malloc( size + 1 )) == NULL)
201
  if((buf = (char *)SMB_MALLOC( size + 1 )) == NULL)
202
  {
202
  {
203
    fprintf(stderr, "%s: malloc fail for size %d.\n", prog_name, size + 1);
203
    fprintf(stderr, "%s: malloc fail for size %d.\n", prog_name, size + 1);
204
    fclose(fp);
204
    fclose(fp);
Lines 398-404 Link Here
398
  } 
398
  } 
399
  
399
  
400
  /* Allocate space for the code page file and read it all in. */
400
  /* Allocate space for the code page file and read it all in. */
401
  if((buf = (char *)malloc( size )) == NULL)
401
  if((buf = (char *)SMB_MALLOC( size )) == NULL)
402
  { 
402
  { 
403
    fprintf (stderr, "%s: malloc fail for size %d.\n",
403
    fprintf (stderr, "%s: malloc fail for size %d.\n",
404
             prog_name, size );
404
             prog_name, size );
(-)samba-2.2.12-pre-CAN-2004-1154/source/utils/make_unicodemap.c (-3 / +3 lines)
Lines 66-72 Link Here
66
  pstring linebuf;
66
  pstring linebuf;
67
  char *p = *buf;
67
  char *p = *buf;
68
  size_t num_lines = 0;
68
  size_t num_lines = 0;
69
  char *newbuf = (char *)malloc( *size + 1);
69
  char *newbuf = (char *)SMB_MALLOC( *size + 1);
70
  char *newbuf_p = NULL;
70
  char *newbuf_p = NULL;
71
71
72
  if(newbuf == NULL) {
72
  if(newbuf == NULL) {
Lines 163-169 Link Here
163
  }
163
  }
164
164
165
  /* As we will be reading text, allocate one more byte for a '\0' */
165
  /* As we will be reading text, allocate one more byte for a '\0' */
166
  if((buf = (char *)malloc( size + 1 )) == NULL) {
166
  if((buf = (char *)SMB_MALLOC( size + 1 )) == NULL) {
167
    fprintf(stderr, "%s: malloc fail for size %d.\n", prog_name, size + 1);
167
    fprintf(stderr, "%s: malloc fail for size %d.\n", prog_name, size + 1);
168
    fclose(fp);
168
    fclose(fp);
169
    exit(1);
169
    exit(1);
Lines 248-254 Link Here
248
248
249
  size = UNICODE_MAP_HEADER_SIZE + (multibyte_code_page ? (4*65536) : (2*256 + 2*65536));
249
  size = UNICODE_MAP_HEADER_SIZE + (multibyte_code_page ? (4*65536) : (2*256 + 2*65536));
250
250
251
  if((output_buf = (char *)malloc( size )) == NULL) {
251
  if((output_buf = (char *)SMB_MALLOC( size )) == NULL) {
252
    fprintf(stderr, "%s: output buffer malloc fail for size %d.\n", prog_name, size);
252
    fprintf(stderr, "%s: output buffer malloc fail for size %d.\n", prog_name, size);
253
    fclose(fp);
253
    fclose(fp);
254
    exit(1);
254
    exit(1);
(-)samba-2.2.12-pre-CAN-2004-1154/source/utils/smbcacls.c (-3 / +3 lines)
Lines 337-343 Link Here
337
		return True;
337
		return True;
338
	}
338
	}
339
339
340
	aces = calloc(1+(*the_acl)->num_aces,sizeof(SEC_ACE));
340
	aces = SMB_XMALLOC_ARRAY( SEC_ACE, 1+(*the_acl)->num_aces );
341
	memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
341
	memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
342
	memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
342
	memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
343
	new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
343
	new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
Lines 365-371 Link Here
365
		}
365
		}
366
366
367
		if (strncmp(tok,"OWNER:", 6) == 0) {
367
		if (strncmp(tok,"OWNER:", 6) == 0) {
368
			owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
368
			owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1 );
369
			if (!owner_sid ||
369
			if (!owner_sid ||
370
			    !StringToSid(owner_sid, tok+6)) {
370
			    !StringToSid(owner_sid, tok+6)) {
371
				printf("Failed to parse owner sid\n");
371
				printf("Failed to parse owner sid\n");
Lines 375-381 Link Here
375
		}
375
		}
376
376
377
		if (strncmp(tok,"GROUP:", 6) == 0) {
377
		if (strncmp(tok,"GROUP:", 6) == 0) {
378
			grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
378
			grp_sid = SMB_CALLOC_ARRAY( DOM_SID, 1);
379
			if (!grp_sid ||
379
			if (!grp_sid ||
380
			    !StringToSid(grp_sid, tok+6)) {
380
			    !StringToSid(grp_sid, tok+6)) {
381
				printf("Failed to parse group sid\n");
381
				printf("Failed to parse group sid\n");
(-)samba-2.2.12-pre-CAN-2004-1154/source/utils/smbpasswd.c (-3 / +2 lines)
Lines 56-62 Link Here
56
56
57
static char *strdup_x(const char *s)
57
static char *strdup_x(const char *s)
58
{
58
{
59
	char *new_s = strdup(s);
59
	char *new_s = SMB_STRDUP(s);
60
	if (!new_s) {
60
	if (!new_s) {
61
		fprintf(stderr,"out of memory\n");
61
		fprintf(stderr,"out of memory\n");
62
		exit(1);
62
		exit(1);
Lines 538-545 Link Here
538
	{
538
	{
539
		UNISTR2 upw;	/* Unicode password */
539
		UNISTR2 upw;	/* Unicode password */
540
540
541
		upw.buffer = (uint16 *)talloc_zero(mem_ctx, 0xc * 
541
		upw.buffer = TALLOC_ZERO_ARRAY(mem_ctx, uint16, 0xc);
542
						   sizeof(uint16));
543
542
544
		upw.uni_str_len = 0xc;
543
		upw.uni_str_len = 0xc;
545
		upw.uni_max_len = 0xc;
544
		upw.uni_max_len = 0xc;
(-)samba-2.2.12-pre-CAN-2004-1154/source/utils/status.c (-1 / +1 lines)
Lines 544-550 Link Here
544
			ptr=ptr->next;
544
			ptr=ptr->next;
545
		}
545
		}
546
		if (ptr==NULL) {
546
		if (ptr==NULL) {
547
			ptr=(struct session_record *) malloc(sizeof(struct session_record));
547
			ptr= SMB_MALLOC_P(struct session_record);
548
			if (!ptr)
548
			if (!ptr)
549
				return 0;
549
				return 0;
550
			ptr->uid=crec.uid;
550
			ptr->uid=crec.uid;
(-)samba-2.2.12-pre-CAN-2004-1154/source/web/cgi.c (-9 / +9 lines)
Lines 91-102 Link Here
91
91
92
	while ((*cl)) {
92
	while ((*cl)) {
93
		int c;
93
		int c;
94
	
94
95
		if (i == len) {
95
		if (i == len) {
96
			char *ret2;
96
			char *ret2;
97
			if (len == 0) len = 1024;
97
			if (len == 0) len = 1024;
98
			else len *= 2;
98
			else len *= 2;
99
			ret2 = (char *)Realloc(ret, len);
99
			ret2 = (char *)SMB_REALLOC(ret, len);
100
			if (!ret2) return ret;
100
			if (!ret2) return ret;
101
			ret = ret2;
101
			ret = ret2;
102
		}
102
		}
Lines 165-172 Link Here
165
			
165
			
166
			*p = 0;
166
			*p = 0;
167
			
167
			
168
			variables[num_variables].name = strdup(line);
168
			variables[num_variables].name = SMB_STRDUP(line);
169
			variables[num_variables].value = strdup(p+1);
169
			variables[num_variables].value = SMB_STRDUP(p+1);
170
170
171
			SAFE_FREE(line);
171
			SAFE_FREE(line);
172
			
172
			
Lines 205-212 Link Here
205
			
205
			
206
			*p = 0;
206
			*p = 0;
207
			
207
			
208
			variables[num_variables].name = strdup(tok);
208
			variables[num_variables].name = SMB_STRDUP(tok);
209
			variables[num_variables].value = strdup(p+1);
209
			variables[num_variables].value = SMB_STRDUP(p+1);
210
210
211
			if (!variables[num_variables].name || 
211
			if (!variables[num_variables].name || 
212
			    !variables[num_variables].value)
212
			    !variables[num_variables].value)
Lines 392-398 Link Here
392
		}
392
		}
393
393
394
		/* Save the users name */
394
		/* Save the users name */
395
		C_user = strdup(user);
395
		C_user = SMB_STRDUP(user);
396
		return True;
396
		return True;
397
	}
397
	}
398
398
Lines 520-530 Link Here
520
		if (line[0] == '\r' || line[0] == '\n') break;
520
		if (line[0] == '\r' || line[0] == '\n') break;
521
		if (strncasecmp(line,"GET ", 4)==0) {
521
		if (strncasecmp(line,"GET ", 4)==0) {
522
			got_request = True;
522
			got_request = True;
523
			url = strdup(&line[4]);
523
			url = SMB_STRDUP(&line[4]);
524
		} else if (strncasecmp(line,"POST ", 5)==0) {
524
		} else if (strncasecmp(line,"POST ", 5)==0) {
525
			got_request = True;
525
			got_request = True;
526
			request_post = 1;
526
			request_post = 1;
527
			url = strdup(&line[5]);
527
			url = SMB_STRDUP(&line[5]);
528
		} else if (strncasecmp(line,"PUT ", 4)==0) {
528
		} else if (strncasecmp(line,"PUT ", 4)==0) {
529
			got_request = True;
529
			got_request = True;
530
			cgi_setup_error("400 Bad Request", "",
530
			cgi_setup_error("400 Bad Request", "",
(-)samba-2.2.12-pre-CAN-2004-1154/source/web/statuspage.c (-2 / +2 lines)
Lines 58-71 Link Here
58
	if (PID_or_Machine) {
58
	if (PID_or_Machine) {
59
		PIDMAP *newmap;
59
		PIDMAP *newmap;
60
60
61
		if ((newmap = (PIDMAP *) malloc (sizeof (PIDMAP))) == NULL) {
61
		if ((newmap = SMB_MALLOC_P(PIDMAP)) == NULL) {
62
			/* XXX need error message for this?
62
			/* XXX need error message for this?
63
			   if malloc fails, PID is always shown */
63
			   if malloc fails, PID is always shown */
64
			return;
64
			return;
65
		}
65
		}
66
66
67
		newmap->pid = pid;
67
		newmap->pid = pid;
68
		newmap->machine = strdup (machine);
68
		newmap->machine = SMB_STRDUP (machine);
69
69
70
		DLIST_ADD(pidmap, newmap);
70
		DLIST_ADD(pidmap, newmap);
71
	}
71
	}
(-)samba-2.2.12-pre-CAN-2004-1154/source/web/swat.c (-2 / +2 lines)
Lines 113-121 Link Here
113
		}
113
		}
114
	}
114
	}
115
	if (length == destlen) {
115
	if (length == destlen) {
116
		return(strdup(str));
116
		return(SMB_STRDUP(str));
117
	}
117
	}
118
	p = dststr = malloc(destlen + 1);
118
	p = dststr = SMB_MALLOC(destlen + 1);
119
	if (!dststr) {
119
	if (!dststr) {
120
		return(NULL);
120
		return(NULL);
121
	}
121
	}

Return to bug 64119