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:53.000000000 +0100
3 +++ samba-2.0.10/source/include/smb.h 2006-03-06 22:27:31.000000000 +0100
8 +#if defined(LARGE_SMB_OFF_T)
9 +#define BUFFER_SIZE (128*1024)
10 +#else /* no large readwrite possible */
11 #define BUFFER_SIZE (0xFFFF)
14 #define SAFETY_MARGIN 1024
15 +#define LARGE_WRITEX_HDR_SIZE 65
18 #define DGRAM_PORT 138
19 diff -ruN samba-2.0.10.orig/source/lib/util_sock.c samba-2.0.10/source/lib/util_sock.c
20 --- samba-2.0.10.orig/source/lib/util_sock.c 2000-03-16 23:59:18.000000000 +0100
21 +++ samba-2.0.10/source/lib/util_sock.c 2006-03-06 22:27:31.000000000 +0100
23 memset(buffer,'\0',smb_size + 100);
25 len = read_smb_length_return_keepalive(fd,buffer,timeout);
29 DEBUG(10,("receive_smb: length < 0!\n"));
33 - if (len > BUFFER_SIZE) {
35 + * A WRITEX with CAP_LARGE_WRITEX can be 64k worth of data plus 65 bytes
36 + * of header. Don't print the error if this fits.... JRA.
39 + if (len > (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE)) {
40 DEBUG(0,("Invalid packet length! (%d bytes).\n",len));
41 if (len > BUFFER_SIZE + (SAFETY_MARGIN/2))
48 ret = read_socket_data(fd,buffer+4,len);
49 diff -ruN samba-2.0.10.orig/source/smbd/oplock.c samba-2.0.10/source/smbd/oplock.c
50 --- samba-2.0.10.orig/source/smbd/oplock.c 2000-04-25 04:32:14.000000000 +0200
51 +++ samba-2.0.10/source/smbd/oplock.c 2006-03-06 22:27:31.000000000 +0100
53 messages crossing on the wire.
56 - if((inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN))==NULL)
57 + if((inbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL)
59 DEBUG(0,("oplock_break: malloc fail for input buffer.\n"));
63 - if((outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN))==NULL)
64 + if((outbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL)
66 DEBUG(0,("oplock_break: malloc fail for output buffer.\n"));
68 diff -ruN samba-2.0.10.orig/source/smbd/process.c samba-2.0.10/source/smbd/process.c
69 --- samba-2.0.10.orig/source/smbd/process.c 2006-03-06 22:25:28.000000000 +0100
70 +++ samba-2.0.10/source/smbd/process.c 2006-03-06 22:27:31.000000000 +0100
72 time_t last_timeout_processing_time = time(NULL);
73 unsigned int num_smbs = 0;
75 - InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
76 - OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
77 + InBuffer = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN);
78 + OutBuffer = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN);
79 if ((InBuffer == NULL) || (OutBuffer == NULL))
83 /* free up temporary memory */
86 - while(!receive_message_or_smb(InBuffer,BUFFER_SIZE,select_timeout,&got_smb))
87 + while(!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout,&got_smb))
89 if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time))
91 diff -ruN samba-2.0.10.orig/source/smbd/reply.c samba-2.0.10/source/smbd/reply.c
92 --- samba-2.0.10.orig/source/smbd/reply.c 2006-03-06 22:25:53.000000000 +0100
93 +++ samba-2.0.10/source/smbd/reply.c 2006-03-06 22:27:31.000000000 +0100
94 @@ -2551,17 +2551,28 @@
95 size_t numtowrite = SVAL(inbuf,smb_vwv10);
96 BOOL write_through = BITSETW(inbuf+smb_vwv7,0);
97 ssize_t nwritten = -1;
98 - int smb_doff = SVAL(inbuf,smb_vwv11);
99 + unsigned int smb_doff = SVAL(inbuf,smb_vwv11);
100 + unsigned int smblen = smb_len(inbuf);
102 + BOOL large_writeX = ((CVAL(inbuf,smb_wct) == 14) && (smblen > 0xFFFF));
104 /* If it's an IPC, pass off the pipe handler. */
106 + if (IS_IPC(conn)) {
107 return reply_pipe_write_and_X(inbuf,outbuf,length,bufsize);
114 + /* Deal with possible LARGE_WRITEX */
116 + numtowrite |= ((((size_t)SVAL(inbuf,smb_vwv9)) & 1 )<<16);
118 + if(smb_doff > smblen || (smb_doff + numtowrite > smblen)) {
119 + return(ERROR(ERRDOS,ERRbadmem));
122 data = smb_base(inbuf) + smb_doff;
124 if(CVAL(inbuf,smb_wct) == 14) {
125 @@ -2586,8 +2597,9 @@
126 #endif /* LARGE_SMB_OFF_T */
129 - if (is_locked(fsp,conn,numtowrite,startpos, F_WRLCK))
130 + if (is_locked(fsp,conn,(SMB_BIG_UINT)numtowrite,(SMB_BIG_UINT)startpos, WRITE_LOCK)) {
131 return(ERROR(ERRDOS,ERRlock));
134 /* X/Open SMB protocol says that, unlike SMBwrite
135 if the length is zero then NO truncation is
136 @@ -2598,12 +2610,15 @@
138 nwritten = write_file(fsp,data,startpos,numtowrite);
140 - if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0))
141 + if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) {
142 return(UNIXERROR(ERRDOS,ERRnoaccess));
145 set_message(outbuf,6,0,True);
147 SSVAL(outbuf,smb_vwv2,nwritten);
149 + SSVAL(outbuf,smb_vwv4,(nwritten>>16)&1);
151 if (nwritten < (ssize_t)numtowrite) {
152 CVAL(outbuf,smb_rcls) = ERRHRD;