1 diff -ruN samba-2.0.10.orig/source/include/smb.h samba-2.0.10/source/include/smb.h
2 --- samba-2.0.10.orig/source/include/smb.h 2006-03-06 22:25:08.000000000 +0100
3 +++ samba-2.0.10/source/include/smb.h 2006-03-06 22:25:53.000000000 +0100
5 #define ERRlock 33 /* Lock request conflicts with existing lock */
6 #define ERRunsup 50 /* Request unsupported, returned by Win 95, RJS 20Jun98 */
7 #define ERRfilexists 80 /* File in operation already exists */
8 +#define ERRinvalidparam 87
9 #define ERRcannotopen 110 /* Cannot open the file specified */
10 #define ERRunknownlevel 124
14 #define SAFE_NETBIOS_CHARS ". -_"
17 +#define SAFE_FREE(x) do { if ((x) != NULL) {free((x)); (x)=NULL;} } while(0)
20 diff -ruN samba-2.0.10.orig/source/include/version.h samba-2.0.10/source/include/version.h
21 --- samba-2.0.10.orig/source/include/version.h 2001-06-23 15:23:59.000000000 +0200
22 +++ samba-2.0.10/source/include/version.h 2006-03-06 22:25:53.000000000 +0100
24 -#define VERSION "2.0.10"
25 +#define VERSION "2.0.10-security-rollup"
26 diff -ruN samba-2.0.10.orig/source/smbd/filename.c samba-2.0.10/source/smbd/filename.c
27 --- samba-2.0.10.orig/source/smbd/filename.c 2000-03-16 23:59:44.000000000 +0100
28 +++ samba-2.0.10/source/smbd/filename.c 2006-03-06 22:25:53.000000000 +0100
30 * StrnCpy always null terminates.
33 - StrnCpy(orig_name, full_orig_name, namelen);
34 + StrnCpy(orig_name, full_orig_name, MIN(namelen, sizeof(orig_name)-1));
36 strupper( orig_name );
38 diff -ruN samba-2.0.10.orig/source/smbd/ipc.c samba-2.0.10/source/smbd/ipc.c
39 --- samba-2.0.10.orig/source/smbd/ipc.c 2006-03-06 22:25:08.000000000 +0100
40 +++ samba-2.0.10/source/smbd/ipc.c 2006-03-06 22:25:53.000000000 +0100
41 @@ -3556,18 +3556,18 @@
44 uint16 vuid = SVAL(inbuf,smb_uid);
45 - int tpscnt = SVAL(inbuf,smb_vwv0);
46 - int tdscnt = SVAL(inbuf,smb_vwv1);
47 - int mprcnt = SVAL(inbuf,smb_vwv2);
48 - int mdrcnt = SVAL(inbuf,smb_vwv3);
49 - int msrcnt = CVAL(inbuf,smb_vwv4);
50 + unsigned int tpscnt = SVAL(inbuf,smb_vwv0);
51 + unsigned int tdscnt = SVAL(inbuf,smb_vwv1);
52 + unsigned int mprcnt = SVAL(inbuf,smb_vwv2);
53 + unsigned int mdrcnt = SVAL(inbuf,smb_vwv3);
54 + unsigned int msrcnt = CVAL(inbuf,smb_vwv4);
55 BOOL close_on_completion = BITSETW(inbuf+smb_vwv5,0);
56 BOOL one_way = BITSETW(inbuf+smb_vwv5,1);
57 - int pscnt = SVAL(inbuf,smb_vwv9);
58 - int psoff = SVAL(inbuf,smb_vwv10);
59 - int dscnt = SVAL(inbuf,smb_vwv11);
60 - int dsoff = SVAL(inbuf,smb_vwv12);
61 - int suwcnt = CVAL(inbuf,smb_vwv13);
62 + unsigned int pscnt = SVAL(inbuf,smb_vwv9);
63 + unsigned int psoff = SVAL(inbuf,smb_vwv10);
64 + unsigned int dscnt = SVAL(inbuf,smb_vwv11);
65 + unsigned int dsoff = SVAL(inbuf,smb_vwv12);
66 + unsigned int suwcnt = CVAL(inbuf,smb_vwv13);
68 memset(name, '\0',sizeof(name));
69 fstrcpy(name,smb_buf(inbuf));
70 @@ -3578,26 +3578,44 @@
73 if((data = (char *)malloc(tdscnt)) == NULL) {
74 - DEBUG(0,("reply_trans: data malloc fail for %d bytes !\n", tdscnt));
75 + DEBUG(0,("reply_trans: data malloc fail for %u bytes !\n", tdscnt));
76 return(ERROR(ERRDOS,ERRnomem));
78 + if ((dsoff+dscnt < dsoff) || (dsoff+dscnt < dscnt))
80 + if (smb_base(inbuf)+dsoff+dscnt > inbuf + size)
83 memcpy(data,smb_base(inbuf)+dsoff,dscnt);
87 if((params = (char *)malloc(tpscnt)) == NULL) {
88 - DEBUG(0,("reply_trans: param malloc fail for %d bytes !\n", tpscnt));
89 + DEBUG(0,("reply_trans: param malloc fail for %u bytes !\n", tpscnt));
91 return(ERROR(ERRDOS,ERRnomem));
93 + if ((psoff+pscnt < psoff) || (psoff+pscnt < pscnt))
95 + if (smb_base(inbuf)+psoff+pscnt > inbuf + size)
98 memcpy(params,smb_base(inbuf)+psoff,pscnt);
103 if((setup = (uint16 *)malloc(suwcnt*sizeof(uint16))) == NULL) {
104 - DEBUG(0,("reply_trans: setup malloc fail for %d bytes !\n", (int)(suwcnt * sizeof(uint16))));
105 - return(ERROR(ERRDOS,ERRnomem));
107 + DEBUG(0,("reply_trans: setup malloc fail for %u bytes !\n", (unsigned int)(suwcnt * sizeof(uint16))));
110 + return(ERROR(ERRDOS,ERRnomem));
112 + if (inbuf+smb_vwv14+(suwcnt*SIZEOFWORD) > inbuf + size)
114 + if ((smb_vwv14+(suwcnt*SIZEOFWORD) < smb_vwv14) || (smb_vwv14+(suwcnt*SIZEOFWORD) < (suwcnt*SIZEOFWORD)))
117 for (i=0;i<suwcnt;i++)
118 setup[i] = SVAL(inbuf,smb_vwv14+i*SIZEOFWORD);
120 @@ -3614,7 +3632,7 @@
121 /* receive the rest of the trans packet */
122 while (pscnt < tpscnt || dscnt < tdscnt) {
124 - int pcnt,poff,dcnt,doff,pdisp,ddisp;
125 + unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
127 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
129 @@ -3625,19 +3643,19 @@
130 DEBUG(0,("reply_trans: %s in getting secondary trans response.\n",
131 (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
142 return(ERROR(ERRSRV,ERRerror));
147 - tpscnt = SVAL(inbuf,smb_vwv0);
148 - tdscnt = SVAL(inbuf,smb_vwv1);
149 + /* Revise total_params and total_data in case they have changed downwards */
150 + if (SVAL(inbuf,smb_vwv0) < tpscnt)
151 + tpscnt = SVAL(inbuf,smb_vwv0);
152 + if (SVAL(inbuf,smb_vwv1) < tdscnt)
153 + tdscnt = SVAL(inbuf,smb_vwv1);
155 pcnt = SVAL(inbuf,smb_vwv2);
156 poff = SVAL(inbuf,smb_vwv3);
157 @@ -3650,17 +3668,36 @@
161 - if (dscnt > tdscnt || pscnt > tpscnt) {
162 - exit_server("invalid trans parameters\n");
164 + if (dscnt > tdscnt || pscnt > tpscnt)
169 + if (pdisp+pcnt >= tpscnt)
171 + if ((pdisp+pcnt < pdisp) || (pdisp+pcnt < pcnt))
173 + if (smb_base(inbuf) + poff + pcnt >= inbuf + bufsize)
175 + if (params + pdisp < params)
178 memcpy(params+pdisp,smb_base(inbuf)+poff,pcnt);
183 + if (ddisp+dcnt >= tdscnt)
185 + if ((ddisp+dcnt < ddisp) || (ddisp+dcnt < dcnt))
187 + if (smb_base(inbuf) + doff + dcnt >= inbuf + bufsize)
189 + if (data + ddisp < data)
192 memcpy(data+ddisp,smb_base(inbuf)+doff,dcnt);
198 DEBUG(3,("trans <%s> data=%d params=%d setup=%d\n",
199 name,tdscnt,tpscnt,suwcnt));
201 @@ -3700,4 +3737,12 @@
202 return(ERROR(ERRSRV,ERRnosupport));
208 + DEBUG(0,("reply_trans: invalid trans parameters\n"));
212 + return(ERROR(ERRSRV,ERRerror));
214 diff -ruN samba-2.0.10.orig/source/smbd/nttrans.c samba-2.0.10/source/smbd/nttrans.c
215 --- samba-2.0.10.orig/source/smbd/nttrans.c 2000-04-24 19:27:30.000000000 +0200
216 +++ samba-2.0.10/source/smbd/nttrans.c 2006-03-06 22:25:53.000000000 +0100
217 @@ -2575,11 +2575,14 @@
218 params = (char *)malloc(total_parameter_count);
219 if (total_data_count > 0)
220 data = (char *)malloc(total_data_count);
223 if ((total_parameter_count && !params) || (total_data_count && !data) ||
224 (setup_count && !setup)) {
228 DEBUG(0,("reply_nttrans : Out of memory\n"));
229 - return(ERROR(ERRDOS,ERRnomem));
230 + return ERROR(ERRDOS,ERRnomem);
233 /* Copy the param and data bytes sent with this request into
234 @@ -2588,64 +2591,112 @@
235 num_data_sofar = data_count;
237 if (parameter_count > total_parameter_count || data_count > total_data_count)
238 - exit_server("reply_nttrans: invalid sizes in packet.\n");
242 - memcpy( setup, &inbuf[smb_nt_SetupStart], setup_count);
243 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count));
244 - dump_data(10, setup, setup_count);
245 + if ((smb_nt_SetupStart + setup_count < smb_nt_SetupStart) ||
246 + (smb_nt_SetupStart + setup_count < setup_count))
248 + if (smb_nt_SetupStart + setup_count > length)
251 + memcpy( setup, &inbuf[smb_nt_SetupStart], setup_count);
254 - memcpy( params, smb_base(inbuf) + parameter_offset, parameter_count);
255 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count));
256 - dump_data(10, params, parameter_count);
257 + if ((parameter_offset + parameter_count < parameter_offset) ||
258 + (parameter_offset + parameter_count < parameter_count))
260 + if (smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length)
263 + memcpy( params, smb_base(inbuf) + parameter_offset, parameter_count);
266 - memcpy( data, smb_base(inbuf) + data_offset, data_count);
267 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count));
268 - dump_data(10, data, data_count);
269 + if ((data_offset + data_count < data_offset) || (data_offset + data_count < data_count))
271 + if (smb_base(inbuf) + data_offset + data_count > inbuf + length)
274 + memcpy( data, smb_base(inbuf) + data_offset, data_count);
278 if(num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
279 /* We need to send an interim response then receive the rest
280 of the parameter/data bytes */
281 outsize = set_message(outbuf,0,0,True);
282 - send_smb(Client,outbuf);
283 + if (!send_smb(Client,outbuf))
284 + exit_server("reply_nttrans: send_smb failed.");
286 while( num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
289 + uint32 parameter_displacement;
290 + uint32 data_displacement;
292 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
295 if((ret && (CVAL(inbuf, smb_com) != SMBnttranss)) || !ret) {
296 - outsize = set_message(outbuf,0,0,True);
298 - DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
300 - DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
301 - (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
302 + outsize = set_message(outbuf,0,0,True);
304 + DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
306 + DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
307 + (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
315 - return(ERROR(ERRSRV,ERRerror));
319 /* Revise total_params and total_data in case they have changed downwards */
320 - total_parameter_count = IVAL(inbuf, smb_nts_TotalParameterCount);
321 - total_data_count = IVAL(inbuf, smb_nts_TotalDataCount);
322 - num_params_sofar += (parameter_count = IVAL(inbuf,smb_nts_ParameterCount));
323 - num_data_sofar += ( data_count = IVAL(inbuf, smb_nts_DataCount));
324 - if (num_params_sofar > total_parameter_count || num_data_sofar > total_data_count)
325 - exit_server("reply_nttrans2: data overflow in secondary nttrans packet\n");
327 - memcpy( ¶ms[ IVAL(inbuf, smb_nts_ParameterDisplacement)],
328 - smb_base(inbuf) + IVAL(inbuf, smb_nts_ParameterOffset), parameter_count);
329 - memcpy( &data[IVAL(inbuf, smb_nts_DataDisplacement)],
330 - smb_base(inbuf)+ IVAL(inbuf, smb_nts_DataOffset), data_count);
331 + if (IVAL(inbuf, smb_nts_TotalParameterCount) < total_parameter_count)
332 + total_parameter_count = IVAL(inbuf, smb_nts_TotalParameterCount);
333 + if (IVAL(inbuf, smb_nts_TotalDataCount) < total_data_count)
334 + total_data_count = IVAL(inbuf, smb_nts_TotalDataCount);
336 + parameter_count = IVAL(inbuf,smb_nts_ParameterCount);
337 + parameter_offset = IVAL(inbuf, smb_nts_ParameterOffset);
338 + parameter_displacement = IVAL(inbuf, smb_nts_ParameterDisplacement);
339 + num_params_sofar += parameter_count;
341 + data_count = IVAL(inbuf, smb_nts_DataCount);
342 + data_displacement = IVAL(inbuf, smb_nts_DataDisplacement);
343 + data_offset = IVAL(inbuf, smb_nts_DataOffset);
344 + num_data_sofar += data_count;
346 + if (num_params_sofar > total_parameter_count || num_data_sofar > total_data_count) {
347 + DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
351 + if (parameter_count) {
352 + if (parameter_displacement + parameter_count >= total_parameter_count)
354 + if ((parameter_displacement + parameter_count < parameter_displacement) ||
355 + (parameter_displacement + parameter_count < parameter_count))
357 + if (smb_base(inbuf) + parameter_offset + parameter_count >= inbuf + bufsize)
359 + if (params + parameter_displacement < params)
362 + memcpy( ¶ms[parameter_displacement], smb_base(inbuf) + parameter_offset, parameter_count);
366 + if (data_displacement + data_count >= total_data_count)
368 + if ((data_displacement + data_count < data_displacement) ||
369 + (data_displacement + data_count < data_count))
371 + if (smb_base(inbuf) + data_offset + data_count >= inbuf + bufsize)
373 + if (data + data_displacement < data)
376 + memcpy( &data[data_displacement], smb_base(inbuf)+ data_offset, data_count);
381 @@ -2714,4 +2765,10 @@
382 return outsize; /* If a correct response was needed the call_nt_transact_xxxx
383 calls have already sent it. If outsize != -1 then it is
384 returning an error packet. */
390 + return ERROR(ERRDOS,ERRinvalidparam);
392 diff -ruN samba-2.0.10.orig/source/smbd/password.c samba-2.0.10/source/smbd/password.c
393 --- samba-2.0.10.orig/source/smbd/password.c 2006-03-06 22:25:08.000000000 +0100
394 +++ samba-2.0.10/source/smbd/password.c 2006-03-06 22:25:53.000000000 +0100
396 if (!ok && lp_username(snum)) {
399 - StrnCpy(user_list,lp_username(snum),sizeof(pstring));
400 + StrnCpy(user_list,lp_username(snum),sizeof(pstring)-1);
402 pstring_sub(user_list,"%S",lp_servicename(snum));
404 diff -ruN samba-2.0.10.orig/source/smbd/reply.c samba-2.0.10/source/smbd/reply.c
405 --- samba-2.0.10.orig/source/smbd/reply.c 2006-03-06 22:25:08.000000000 +0100
406 +++ samba-2.0.10/source/smbd/reply.c 2006-03-06 22:25:53.000000000 +0100
407 @@ -1413,6 +1413,9 @@
409 for (i=numentries;(i<maxentries) && !finished;i++)
411 + /* check to make sure we have room in the buffer */
412 + if ( ((PTR_DIFF(p, outbuf))+DIR_STRUCT_SIZE) > BUFFER_SIZE )
415 !get_dir_entry(conn,mask,dirtype,fname,&size,&mode,&date,check_descend);
417 @@ -3122,6 +3125,9 @@
420 for (i=first;i<first+num_to_get;i++) {
421 + /* check to make sure we have room in the buffer */
422 + if ( (PTR_DIFF(p, outbuf)+28) > BUFFER_SIZE )
424 put_dos_date2(p,0,queue[i].time);
425 CVAL(p,4) = (queue[i].status==LPQ_PRINTING?2:3);
426 SSVAL(p,5,printjob_encode(SNUM(conn),
427 diff -ruN samba-2.0.10.orig/source/smbd/trans2.c samba-2.0.10/source/smbd/trans2.c
428 --- samba-2.0.10.orig/source/smbd/trans2.c 2000-04-24 19:27:31.000000000 +0200
429 +++ samba-2.0.10/source/smbd/trans2.c 2006-03-06 22:25:53.000000000 +0100
431 int16 open_ofun = SVAL(params,12);
432 int32 open_size = IVAL(params,14);
433 char *pname = ¶ms[28];
434 - int16 namelen = strlen(pname)+1;
439 BOOL bad_path = False;
442 - StrnCpy(fname,pname,namelen);
443 + pstrcpy(fname,pname);
445 DEBUG(3,("trans2open %s mode=%d attr=%d ofun=%d size=%d\n",
446 fname,open_mode, open_attr, open_ofun, open_size));
447 @@ -2185,7 +2184,7 @@
448 unsigned int suwcnt = SVAL(inbuf, smb_suwcnt);
449 unsigned int tran_call = SVAL(inbuf, smb_setup0);
450 char *params = NULL, *data = NULL;
451 - int num_params, num_params_sofar, num_data, num_data_sofar;
452 + unsigned int num_params, num_params_sofar, num_data, num_data_sofar;
454 if(global_oplock_break && (tran_call == TRANSACT2_OPEN)) {
455 /* Queue this open message as we are the process of an
456 @@ -2203,8 +2202,9 @@
457 /* All trans2 messages we handle have smb_sucnt == 1 - ensure this
458 is so as a sanity check */
460 - DEBUG(2,("Invalid smb_sucnt in trans2 call\n"));
461 - return(ERROR(ERRSRV,ERRerror));
462 + DEBUG(2,("Invalid smb_sucnt in trans2 call(%u)\n",suwcnt));
463 + DEBUG(2,("Transaction is %d\n",tran_call));
464 + ERROR(ERRDOS,ERRinvalidparam);
467 /* Allocate the space for the maximum needed parameters and data */
468 @@ -2215,11 +2215,9 @@
470 if ((total_params && !params) || (total_data && !data)) {
471 DEBUG(2,("Out of memory in reply_trans2\n"));
476 - return(ERROR(ERRDOS,ERRnomem));
479 + return ERROR(ERRDOS,ERRnomem);
482 /* Copy the param and data bytes sent with this request into
483 @@ -2230,20 +2228,37 @@
484 if (num_params > total_params || num_data > total_data)
485 exit_server("invalid params in reply_trans2");
488 - memcpy( params, smb_base(inbuf) + SVAL(inbuf, smb_psoff), num_params);
490 - memcpy( data, smb_base(inbuf) + SVAL(inbuf, smb_dsoff), num_data);
492 + unsigned int psoff = SVAL(inbuf, smb_psoff);
493 + if ((psoff + num_params < psoff) || (psoff + num_params < num_params))
495 + if (smb_base(inbuf) + psoff + num_params > inbuf + length)
497 + memcpy( params, smb_base(inbuf) + psoff, num_params);
500 + unsigned int dsoff = SVAL(inbuf, smb_dsoff);
501 + if ((dsoff + num_data < dsoff) || (dsoff + num_data < num_data))
503 + if (smb_base(inbuf) + dsoff + num_data > inbuf + length)
505 + memcpy( data, smb_base(inbuf) + dsoff, num_data);
508 if(num_data_sofar < total_data || num_params_sofar < total_params) {
509 /* We need to send an interim response then receive the rest
510 of the parameter/data bytes */
511 outsize = set_message(outbuf,0,0,True);
512 - send_smb(Client,outbuf);
513 + if (!send_smb(Client,outbuf))
514 + exit_server("reply_trans2: send_smb failed.");
516 while (num_data_sofar < total_data ||
517 num_params_sofar < total_params) {
519 + unsigned int param_disp;
520 + unsigned int param_off;
521 + unsigned int data_disp;
522 + unsigned int data_off;
524 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
526 @@ -2255,26 +2270,55 @@
528 DEBUG(0,("reply_trans2: %s in getting secondary trans2 response.\n",
529 (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
534 - return(ERROR(ERRSRV,ERRerror));
538 /* Revise total_params and total_data in case
539 they have changed downwards */
540 - total_params = SVAL(inbuf, smb_tpscnt);
541 - total_data = SVAL(inbuf, smb_tdscnt);
542 - num_params_sofar += (num_params = SVAL(inbuf,smb_spscnt));
543 - num_data_sofar += ( num_data = SVAL(inbuf, smb_sdscnt));
544 + if (SVAL(inbuf, smb_tpscnt) < total_params)
545 + total_params = SVAL(inbuf, smb_tpscnt);
546 + if (SVAL(inbuf, smb_tdscnt) < total_data)
547 + total_data = SVAL(inbuf, smb_tdscnt);
549 + num_params = SVAL(inbuf,smb_spscnt);
550 + param_off = SVAL(inbuf, smb_spsoff);
551 + param_disp = SVAL(inbuf, smb_spsdisp);
552 + num_params_sofar += num_params;
554 + num_data = SVAL(inbuf, smb_sdscnt);
555 + data_off = SVAL(inbuf, smb_sdsoff);
556 + data_disp = SVAL(inbuf, smb_sdsdisp);
557 + num_data_sofar += num_data;
559 if (num_params_sofar > total_params || num_data_sofar > total_data)
560 - exit_server("data overflow in trans2");
563 - memcpy( ¶ms[ SVAL(inbuf, smb_spsdisp)],
564 - smb_base(inbuf) + SVAL(inbuf, smb_spsoff), num_params);
565 - memcpy( &data[SVAL(inbuf, smb_sdsdisp)],
566 - smb_base(inbuf)+ SVAL(inbuf, smb_sdsoff), num_data);
568 + if (param_disp + num_params >= total_params)
570 + if ((param_disp + num_params < param_disp) ||
571 + (param_disp + num_params < num_params))
573 + if (smb_base(inbuf) + param_off + num_params >= inbuf + bufsize)
575 + if (params + param_disp < params)
578 + memcpy( ¶ms[param_disp], smb_base(inbuf) + param_off, num_params);
581 + if (data_disp + num_data >= total_data)
583 + if ((data_disp + num_data < data_disp) ||
584 + (data_disp + num_data < num_data))
586 + if (smb_base(inbuf) + data_off + num_data >= inbuf + bufsize)
588 + if (data + data_disp < data)
591 + memcpy( &data[data_disp], smb_base(inbuf) + data_off, num_data);
596 @@ -2367,4 +2411,10 @@
597 return outsize; /* If a correct response was needed the
598 call_trans2xxx calls have already sent
599 it. If outsize != -1 then it is returning */
605 + return (ERROR(ERRDOS,ERRinvalidparam));