Add a "buflen" struct member to smb_request
authorVolker Lendecke <vl@samba.org>
Sat, 1 Nov 2008 15:24:42 +0000 (16:24 +0100)
committerVolker Lendecke <vl@samba.org>
Sat, 1 Nov 2008 18:41:07 +0000 (19:41 +0100)
This removes some explicit inbuf references and also removes a pointless check
in reply_echo. The buflen can never be more than 64k, this is just a 16 bit
value.

source3/include/smb.h
source3/smbd/process.c
source3/smbd/reply.c
source3/smbd/sesssetup.c

index fdbad2a22a2a58cdc075facfc42ef2c17217ab1a..d682052c6369d5b5e125cb8dec28af235bc84d9d 100644 (file)
@@ -631,6 +631,7 @@ struct smb_request {
        uint16 vuid;
        uint16 tid;
        uint8  wct;
+       uint16_t buflen;
        const uint8 *inbuf;
        uint8 *outbuf;
        size_t unread_bytes;
index 4d415b2d2771631e54df5a7a79a6478e21da2ae8..8e1add3fb14fd6c41046a0bfab43299ff2cf1c53 100644 (file)
@@ -375,6 +375,7 @@ void init_smb_request(struct smb_request *req,
        req->vuid   = SVAL(inbuf, smb_uid);
        req->tid    = SVAL(inbuf, smb_tid);
        req->wct    = CVAL(inbuf, smb_wct);
+       req->buflen = smb_buflen(inbuf);
        req->unread_bytes = unread_bytes;
        req->encrypted = encrypted;
        req->conn = conn_find(req->tid);
@@ -388,10 +389,10 @@ void init_smb_request(struct smb_request *req,
                exit_server_cleanly("Invalid SMB request");
        }
        /* Ensure bcc is correct. */
-       if (((uint8 *)smb_buf(inbuf)) + smb_buflen(inbuf) > inbuf + req_size) {
+       if (((uint8 *)smb_buf(inbuf)) + req->buflen > inbuf + req_size) {
                DEBUG(0,("init_smb_request: invalid bcc number %u "
                        "(wct = %u, size %u)\n",
-                       (unsigned int)smb_buflen(inbuf),
+                       (unsigned int)req->buflen,
                        (unsigned int)req->wct,
                        (unsigned int)req_size));
                exit_server_cleanly("Invalid SMB request");
index 25480c6e3b143ee9eb81a7b337eaf34e0f200c53..2d7e55798065b6517bf6511b0d5338f75f107c5d 100644 (file)
@@ -523,7 +523,7 @@ void reply_tcon(struct smb_request *req)
 
        START_PROFILE(SMBtcon);
 
-       if (smb_buflen(req->inbuf) < 4) {
+       if (req->buflen < 4) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                END_PROFILE(SMBtcon);
                return;
@@ -614,7 +614,7 @@ void reply_tcon_and_X(struct smb_request *req)
                conn = NULL;
        }
 
-       if ((passlen > MAX_PASS_LEN) || (passlen >= smb_buflen(req->inbuf))) {
+       if ((passlen > MAX_PASS_LEN) || (passlen >= req->buflen)) {
                reply_doserror(req, ERRDOS, ERRbuftoosmall);
                END_PROFILE(SMBtconX);
                return;
@@ -4562,7 +4562,6 @@ void reply_echo(struct smb_request *req)
        connection_struct *conn = req->conn;
        int smb_reverb;
        int seq_num;
-       unsigned int data_len = smb_buflen(req->inbuf);
 
        START_PROFILE(SMBecho);
 
@@ -4572,20 +4571,13 @@ void reply_echo(struct smb_request *req)
                return;
        }
 
-       if (data_len > BUFFER_SIZE) {
-               DEBUG(0,("reply_echo: data_len too large.\n"));
-               reply_nterror(req, NT_STATUS_INSUFFICIENT_RESOURCES);
-               END_PROFILE(SMBecho);
-               return;
-       }
-
        smb_reverb = SVAL(req->inbuf,smb_vwv0);
 
-       reply_outbuf(req, 1, data_len);
+       reply_outbuf(req, 1, req->buflen);
 
        /* copy any incoming data back out */
-       if (data_len > 0) {
-               memcpy(smb_buf(req->outbuf),smb_buf(req->inbuf),data_len);
+       if (req->buflen > 0) {
+               memcpy(smb_buf(req->outbuf), smb_buf(req->inbuf), req->buflen);
        }
 
        if (smb_reverb > 100) {
@@ -4835,7 +4827,7 @@ void reply_printwrite(struct smb_request *req)
 
        numtowrite = SVAL(smb_buf(req->inbuf),1);
 
-       if (smb_buflen(req->inbuf) < numtowrite + 3) {
+       if (req->buflen < numtowrite + 3) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                END_PROFILE(SMBsplwr);
                return;
@@ -6746,7 +6738,7 @@ void reply_lockingX(struct smb_request *req)
 
        release_level_2_oplocks_on_change(fsp);
 
-       if (smb_buflen(req->inbuf) <
+       if (req->buflen <
            (num_ulocks + num_locks) * (large_file_format ? 20 : 10)) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                END_PROFILE(SMBlockingX);
index b2583861217f93ead7d082233283f4280132d5c0..02931e49f4ce5f6e9d62be1ab60326f468aa1a95 100644 (file)
@@ -1446,8 +1446,7 @@ void reply_sesssetup_and_X(struct smb_request *req)
                 * don't get client caps. */
                remove_from_common_flags2(FLAGS2_32_BIT_ERROR_CODES);
 
-               if ((passlen1 > MAX_PASS_LEN)
-                   || (passlen1 > smb_buflen(req->inbuf))) {
+               if ((passlen1 > MAX_PASS_LEN) || (passlen1 > req->buflen)) {
                        reply_nterror(req, nt_status_squash(
                                              NT_STATUS_INVALID_PARAMETER));
                        END_PROFILE(SMBsesssetupX);