s3:rpc_server/svcctl: fix valgrind bugs in _svcctl_QueryServiceConfig2W()
authorStefan Metzmacher <metze@samba.org>
Thu, 16 Jun 2011 10:34:42 +0000 (12:34 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 16 Jun 2011 10:40:14 +0000 (12:40 +0200)
r->out.buffer needs to stay in its size, as it will be marshalled completely.
As it's preallocated and initialized with zeros, we just need to copy
the payload into it.

If we always marshall the return buffer, we already have the needed
buffer size and don't need to call ndr_size_* functions.

metze

source3/rpc_server/svcctl/srv_svcctl_nt.c

index 4f8a2c1b7da851595d2324aac0f80ac428c7e8dd..8523def037b9e36843f315c40f9ca54bd5181e3a 100644 (file)
@@ -775,7 +775,8 @@ WERROR _svcctl_QueryServiceConfig2W(struct pipes_struct *p,
                                    struct svcctl_QueryServiceConfig2W *r)
 {
        SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
-       uint32 buffer_size;
+       uint32_t buffer_size;
+       DATA_BLOB blob = data_blob_null;
 
        /* perform access checks */
 
@@ -795,7 +796,6 @@ WERROR _svcctl_QueryServiceConfig2W(struct pipes_struct *p,
                        struct SERVICE_DESCRIPTION desc_buf;
                        const char *description;
                        enum ndr_err_code ndr_err;
-                       DATA_BLOB blob;
 
                        description = svcctl_lookup_description(p->mem_ctx,
                                                                p->msg_ctx,
@@ -810,9 +810,6 @@ WERROR _svcctl_QueryServiceConfig2W(struct pipes_struct *p,
                                return WERR_INVALID_PARAM;
                        }
 
-                       buffer_size = ndr_size_SERVICE_DESCRIPTION(&desc_buf, 0);
-                       r->out.buffer = blob.data;
-
                        break;
                }
                break;
@@ -820,7 +817,6 @@ WERROR _svcctl_QueryServiceConfig2W(struct pipes_struct *p,
                {
                        struct SERVICE_FAILURE_ACTIONS actions;
                        enum ndr_err_code ndr_err;
-                       DATA_BLOB blob;
 
                        /* nothing to say...just service the request */
 
@@ -832,9 +828,6 @@ WERROR _svcctl_QueryServiceConfig2W(struct pipes_struct *p,
                                return WERR_INVALID_PARAM;
                        }
 
-                       buffer_size = ndr_size_SERVICE_FAILURE_ACTIONS(&actions, 0);
-                       r->out.buffer = blob.data;
-
                        break;
                }
                break;
@@ -843,12 +836,15 @@ WERROR _svcctl_QueryServiceConfig2W(struct pipes_struct *p,
                return WERR_UNKNOWN_LEVEL;
        }
 
+       buffer_size = blob.length;
        buffer_size += buffer_size % 4;
        *r->out.needed = (buffer_size > r->in.offered) ? buffer_size : r->in.offered;
 
         if (buffer_size > r->in.offered)
                 return WERR_INSUFFICIENT_BUFFER;
 
+       memcpy(r->out.buffer, blob.data, blob.length);
+
        return WERR_OK;
 }