Modify fill_ea_chained_buffer() to be able to do size calculation only, no marshalling.
authorJeremy Allison <jra@samba.org>
Tue, 26 Mar 2013 22:46:06 +0000 (15:46 -0700)
committerDavid Disseldorp <ddiss@samba.org>
Tue, 2 Apr 2013 18:06:37 +0000 (20:06 +0200)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: David Disseldorp <ddiss@suse.de>
source3/smbd/trans2.c

index ee16bf9b533234fb8b6dc8a8ae1c1628d9f7c832..61252ba50736f306f4d91f368abbfb4d2ed43d0d 100644 (file)
@@ -459,6 +459,7 @@ static NTSTATUS fill_ea_chained_buffer(TALLOC_CTX *mem_ctx,
 {
        uint8_t *p = (uint8_t *)pdata;
        uint8_t *last_start = NULL;
+       bool do_store_data = (pdata != NULL);
 
        *ret_data_size = 0;
 
@@ -471,7 +472,7 @@ static NTSTATUS fill_ea_chained_buffer(TALLOC_CTX *mem_ctx,
                fstring dos_ea_name;
                size_t this_size;
 
-               if (last_start) {
+               if (last_start != NULL && do_store_data) {
                        SIVAL(last_start, 0, PTR_DIFF(p, last_start));
                }
                last_start = p;
@@ -492,19 +493,21 @@ static NTSTATUS fill_ea_chained_buffer(TALLOC_CTX *mem_ctx,
                        this_size += pad;
                }
 
-               if (this_size > total_data_size) {
-                       return NT_STATUS_INFO_LENGTH_MISMATCH;
+               if (do_store_data) {
+                       if (this_size > total_data_size) {
+                               return NT_STATUS_INFO_LENGTH_MISMATCH;
+                       }
+
+                       /* We know we have room. */
+                       SIVAL(p, 0x00, 0); /* next offset */
+                       SCVAL(p, 0x04, ea_list->ea.flags);
+                       SCVAL(p, 0x05, dos_namelen);
+                       SSVAL(p, 0x06, ea_list->ea.value.length);
+                       strlcpy((char *)(p+0x08), dos_ea_name, dos_namelen+1);
+                       memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
+                       total_data_size -= this_size;
                }
 
-               /* We know we have room. */
-               SIVAL(p, 0x00, 0); /* next offset */
-               SCVAL(p, 0x04, ea_list->ea.flags);
-               SCVAL(p, 0x05, dos_namelen);
-               SSVAL(p, 0x06, ea_list->ea.value.length);
-               strlcpy((char *)(p+0x08), dos_ea_name, dos_namelen+1);
-               memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
-
-               total_data_size -= this_size;
                p += this_size;
        }