From aadf4a638366484f64e12d161ad8d90769a04947 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 25 Nov 2009 14:21:32 +0100 Subject: [PATCH 1/4] pidl:NDR/Parser: $size can be 'foo / 2' so we need to add '(' and ')' foo / 5 * sizeof(bar)' isn't the same as '(foo / 2) * sizeof(bar)'. metze (cherry picked from commit ab1c92950f3cfdc8c52b772ecef23a5477f48f9d) --- pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index 7ce9708..a5ee948 100644 --- a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -2119,7 +2119,7 @@ sub AllocateArrayLevel($$$$$$) $self->pidl("}"); if (grep(/in/,@{$e->{DIRECTION}}) and grep(/out/,@{$e->{DIRECTION}})) { - $self->pidl("memcpy(r->out.$e->{NAME}, r->in.$e->{NAME}, $size * sizeof(*r->in.$e->{NAME}));"); + $self->pidl("memcpy(r->out.$e->{NAME}, r->in.$e->{NAME}, ($size) * sizeof(*r->in.$e->{NAME}));"); } return; } -- 1.6.5.2 From a61ccb205212961a06463d4284ffc9785a7cfd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 27 Nov 2009 11:37:01 +0100 Subject: [PATCH 2/4] pidl:Samba3/ClientNDR: $size can be 'foo / 2' so we need to add '(' and ')' foo / 5 * sizeof(bar)' isn't the same as '(foo / 2) * sizeof(bar)'. metze --- pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 4 ++-- pidl/tests/samba3-cli.pl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index ed1b71a..9a29214 100644 --- a/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -98,9 +98,9 @@ sub ParseOutputArgument($$$) my $env = GenerateFunctionInEnv($fn, "r."); my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL}); if (has_property($e, "charset")) { - $self->pidl("memcpy(CONST_DISCARD(char *, $e->{NAME}), r.out.$e->{NAME}, $size_is * sizeof(*$e->{NAME}));"); + $self->pidl("memcpy(discard_const_p(uint8_t, $e->{NAME}), r.out.$e->{NAME}, ($size_is) * sizeof(*$e->{NAME}));"); } else { - $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is * sizeof(*$e->{NAME}));"); + $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, ($size_is) * sizeof(*$e->{NAME}));"); } } else { $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};"); diff --git a/pidl/tests/samba3-cli.pl b/pidl/tests/samba3-cli.pl index 5a55163..27ab99d 100755 --- a/pidl/tests/samba3-cli.pl +++ b/pidl/tests/samba3-cli.pl @@ -123,4 +123,4 @@ my $e = { NAME => "foo", ORIGINAL => { FILE => "f", LINE => -1 }, LEVELS => [ { TYPE => "ARRAY", SIZE_IS => "mysize" }, { TYPE => "DATA", DATA_TYPE => "int" } ]}; $x->ParseOutputArgument($fn, $e); -is($x->{res}, "memcpy(foo, r.out.foo, mysize * sizeof(*foo));\n"); +is($x->{res}, "memcpy(foo, r.out.foo, (mysize) * sizeof(*foo));\n"); -- 1.6.5.2 From f8aa85b23d380d4616be6b506fe5e21a8e3057a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 27 Nov 2009 16:44:39 +0100 Subject: [PATCH 3/4] pidl: fix handling of output arguments in s3 client stubs. a20e095 used (uint8_t) instead of (uint8_t *). Guenther --- pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 9a29214..a45abdb 100644 --- a/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -98,7 +98,7 @@ sub ParseOutputArgument($$$) my $env = GenerateFunctionInEnv($fn, "r."); my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL}); if (has_property($e, "charset")) { - $self->pidl("memcpy(discard_const_p(uint8_t, $e->{NAME}), r.out.$e->{NAME}, ($size_is) * sizeof(*$e->{NAME}));"); + $self->pidl("memcpy(discard_const_p(uint8_t *, $e->{NAME}), r.out.$e->{NAME}, ($size_is) * sizeof(*$e->{NAME}));"); } else { $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, ($size_is) * sizeof(*$e->{NAME}));"); } -- 1.6.5.2 From f0fec8a6161a3b5c16932711e4f4bf8c292537f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 27 Nov 2009 16:49:48 +0100 Subject: [PATCH 4/4] s3: re-run make samba3-idl. Guenther --- librpc/gen_ndr/cli_echo.c | 4 ++-- librpc/gen_ndr/cli_epmapper.c | 4 ++-- librpc/gen_ndr/cli_eventlog.c | 4 ++-- librpc/gen_ndr/cli_ntsvcs.c | 4 ++-- librpc/gen_ndr/cli_spoolss.c | 12 ++++++------ librpc/gen_ndr/cli_srvsvc.c | 2 +- librpc/gen_ndr/cli_svcctl.c | 20 ++++++++++---------- librpc/gen_ndr/cli_winreg.c | 8 ++++---- librpc/gen_ndr/ndr_winreg.c | 4 ++-- source3/librpc/gen_ndr/messaging.h | 2 ++ source3/librpc/gen_ndr/notify.h | 2 ++ 11 files changed, 35 insertions(+), 31 deletions(-) diff --git a/librpc/gen_ndr/cli_echo.c b/librpc/gen_ndr/cli_echo.c index ff369c7..48632a3 100644 --- a/librpc/gen_ndr/cli_echo.c +++ b/librpc/gen_ndr/cli_echo.c @@ -82,7 +82,7 @@ NTSTATUS rpccli_echo_EchoData(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(out_data, r.out.out_data, r.in.len * sizeof(*out_data)); + memcpy(out_data, r.out.out_data, (r.in.len) * sizeof(*out_data)); /* Return result */ return NT_STATUS_OK; @@ -162,7 +162,7 @@ NTSTATUS rpccli_echo_SourceData(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(data, r.out.data, r.in.len * sizeof(*data)); + memcpy(data, r.out.data, (r.in.len) * sizeof(*data)); /* Return result */ return NT_STATUS_OK; diff --git a/librpc/gen_ndr/cli_epmapper.c b/librpc/gen_ndr/cli_epmapper.c index 0ccefa9..65621d3 100644 --- a/librpc/gen_ndr/cli_epmapper.c +++ b/librpc/gen_ndr/cli_epmapper.c @@ -135,7 +135,7 @@ NTSTATUS rpccli_epm_Lookup(struct rpc_pipe_client *cli, /* Return variables */ *entry_handle = *r.out.entry_handle; *num_ents = *r.out.num_ents; - memcpy(entries, r.out.entries, r.in.max_ents * sizeof(*entries)); + memcpy(entries, r.out.entries, (r.in.max_ents) * sizeof(*entries)); /* Return result */ return NT_STATUS_OK; @@ -184,7 +184,7 @@ NTSTATUS rpccli_epm_Map(struct rpc_pipe_client *cli, /* Return variables */ *entry_handle = *r.out.entry_handle; *num_towers = *r.out.num_towers; - memcpy(towers, r.out.towers, r.in.max_towers * sizeof(*towers)); + memcpy(towers, r.out.towers, (r.in.max_towers) * sizeof(*towers)); /* Return result */ return NT_STATUS_OK; diff --git a/librpc/gen_ndr/cli_eventlog.c b/librpc/gen_ndr/cli_eventlog.c index b9cf39d..2480412 100644 --- a/librpc/gen_ndr/cli_eventlog.c +++ b/librpc/gen_ndr/cli_eventlog.c @@ -464,7 +464,7 @@ NTSTATUS rpccli_eventlog_ReadEventLogW(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(data, r.out.data, r.in.number_of_bytes * sizeof(*data)); + memcpy(data, r.out.data, (r.in.number_of_bytes) * sizeof(*data)); *sent_size = *r.out.sent_size; *real_size = *r.out.real_size; @@ -941,7 +941,7 @@ NTSTATUS rpccli_eventlog_GetLogInformation(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(buffer, r.out.buffer, r.in.buf_size * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (r.in.buf_size) * sizeof(*buffer)); *bytes_needed = *r.out.bytes_needed; /* Return result */ diff --git a/librpc/gen_ndr/cli_ntsvcs.c b/librpc/gen_ndr/cli_ntsvcs.c index 179368d..8f98278 100644 --- a/librpc/gen_ndr/cli_ntsvcs.c +++ b/librpc/gen_ndr/cli_ntsvcs.c @@ -461,7 +461,7 @@ NTSTATUS rpccli_PNP_GetDeviceList(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(buffer, r.out.buffer, *r.in.length * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (*r.in.length) * sizeof(*buffer)); *length = *r.out.length; /* Return result */ @@ -606,7 +606,7 @@ NTSTATUS rpccli_PNP_GetDeviceRegProp(struct rpc_pipe_client *cli, /* Return variables */ *reg_data_type = *r.out.reg_data_type; - memcpy(buffer, r.out.buffer, *r.in.buffer_size * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (*r.in.buffer_size) * sizeof(*buffer)); *buffer_size = *r.out.buffer_size; *needed = *r.out.needed; diff --git a/librpc/gen_ndr/cli_spoolss.c b/librpc/gen_ndr/cli_spoolss.c index 1e94a2a..3dd73c6 100644 --- a/librpc/gen_ndr/cli_spoolss.c +++ b/librpc/gen_ndr/cli_spoolss.c @@ -1144,7 +1144,7 @@ NTSTATUS rpccli_spoolss_ReadPrinter(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(data, r.out.data, r.in.data_size * sizeof(*data)); + memcpy(data, r.out.data, (r.in.data_size) * sizeof(*data)); *_data_size = *r.out._data_size; /* Return result */ @@ -1240,7 +1240,7 @@ NTSTATUS rpccli_spoolss_AddJob(struct rpc_pipe_client *cli, /* Return variables */ if (buffer && r.out.buffer) { - memcpy(buffer, r.out.buffer, r.in.offered * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (r.in.offered) * sizeof(*buffer)); } *needed = *r.out.needed; @@ -3464,10 +3464,10 @@ NTSTATUS rpccli_spoolss_EnumPrinterData(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(CONST_DISCARD(char *, value_name), r.out.value_name, r.in.value_offered / 2 * sizeof(*value_name)); + memcpy(discard_const_p(uint8_t *, value_name), r.out.value_name, (r.in.value_offered / 2) * sizeof(*value_name)); *value_needed = *r.out.value_needed; *type = *r.out.type; - memcpy(data, r.out.data, r.in.data_offered * sizeof(*data)); + memcpy(data, r.out.data, (r.in.data_offered) * sizeof(*data)); *data_needed = *r.out.data_needed; /* Return result */ @@ -3743,7 +3743,7 @@ NTSTATUS rpccli_spoolss_GetPrinterDataEx(struct rpc_pipe_client *cli, /* Return variables */ *type = *r.out.type; - memcpy(buffer, r.out.buffer, r.in.offered * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (r.in.offered) * sizeof(*buffer)); *needed = *r.out.needed; /* Return result */ @@ -4211,7 +4211,7 @@ NTSTATUS rpccli_spoolss_XcvData(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(out_data, r.out.out_data, r.in.out_data_size * sizeof(*out_data)); + memcpy(out_data, r.out.out_data, (r.in.out_data_size) * sizeof(*out_data)); *needed = *r.out.needed; *status_code = *r.out.status_code; diff --git a/librpc/gen_ndr/cli_srvsvc.c b/librpc/gen_ndr/cli_srvsvc.c index d372510..9dd4162 100644 --- a/librpc/gen_ndr/cli_srvsvc.c +++ b/librpc/gen_ndr/cli_srvsvc.c @@ -1622,7 +1622,7 @@ NTSTATUS rpccli_srvsvc_NetPathCanonicalize(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(can_path, r.out.can_path, r.in.maxbuf * sizeof(*can_path)); + memcpy(can_path, r.out.can_path, (r.in.maxbuf) * sizeof(*can_path)); *pathtype = *r.out.pathtype; /* Return result */ diff --git a/librpc/gen_ndr/cli_svcctl.c b/librpc/gen_ndr/cli_svcctl.c index a95a4e7..de23fd9 100644 --- a/librpc/gen_ndr/cli_svcctl.c +++ b/librpc/gen_ndr/cli_svcctl.c @@ -225,7 +225,7 @@ NTSTATUS rpccli_svcctl_QueryServiceObjectSecurity(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(buffer, r.out.buffer, r.in.offered * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (r.in.offered) * sizeof(*buffer)); *needed = *r.out.needed; /* Return result */ @@ -685,7 +685,7 @@ NTSTATUS rpccli_svcctl_EnumDependentServicesW(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(service_status, r.out.service_status, r.in.offered * sizeof(*service_status)); + memcpy(service_status, r.out.service_status, (r.in.offered) * sizeof(*service_status)); *needed = *r.out.needed; *services_returned = *r.out.services_returned; @@ -742,7 +742,7 @@ NTSTATUS rpccli_svcctl_EnumServicesStatusW(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(service, r.out.service, r.in.offered * sizeof(*service)); + memcpy(service, r.out.service, (r.in.offered) * sizeof(*service)); *needed = *r.out.needed; *services_returned = *r.out.services_returned; if (resume_handle && r.out.resume_handle) { @@ -1385,7 +1385,7 @@ NTSTATUS rpccli_svcctl_EnumServicesStatusA(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(service, r.out.service, r.in.offered * sizeof(*service)); + memcpy(service, r.out.service, (r.in.offered) * sizeof(*service)); *needed = *r.out.needed; *services_returned = *r.out.services_returned; if (resume_handle && r.out.resume_handle) { @@ -1534,7 +1534,7 @@ NTSTATUS rpccli_svcctl_QueryServiceConfigA(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(query, r.out.query, r.in.offered * sizeof(*query)); + memcpy(query, r.out.query, (r.in.offered) * sizeof(*query)); *needed = *r.out.needed; /* Return result */ @@ -1961,7 +1961,7 @@ NTSTATUS rpccli_svcctl_QueryServiceConfig2A(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(buffer, r.out.buffer, r.in.offered * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (r.in.offered) * sizeof(*buffer)); *needed = *r.out.needed; /* Return result */ @@ -2012,7 +2012,7 @@ NTSTATUS rpccli_svcctl_QueryServiceConfig2W(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(buffer, r.out.buffer, r.in.offered * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (r.in.offered) * sizeof(*buffer)); *needed = *r.out.needed; /* Return result */ @@ -2063,7 +2063,7 @@ NTSTATUS rpccli_svcctl_QueryServiceStatusEx(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(buffer, r.out.buffer, r.in.offered * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (r.in.offered) * sizeof(*buffer)); *needed = *r.out.needed; /* Return result */ @@ -2122,7 +2122,7 @@ NTSTATUS rpccli_EnumServicesStatusExA(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(services, r.out.services, r.in.offered * sizeof(*services)); + memcpy(services, r.out.services, (r.in.offered) * sizeof(*services)); *needed = *r.out.needed; *service_returned = *r.out.service_returned; if (resume_handle && r.out.resume_handle) { @@ -2187,7 +2187,7 @@ NTSTATUS rpccli_EnumServicesStatusExW(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(services, r.out.services, r.in.offered * sizeof(*services)); + memcpy(services, r.out.services, (r.in.offered) * sizeof(*services)); *needed = *r.out.needed; *service_returned = *r.out.service_returned; if (resume_handle && r.out.resume_handle) { diff --git a/librpc/gen_ndr/cli_winreg.c b/librpc/gen_ndr/cli_winreg.c index b18554e..c5d19be 100644 --- a/librpc/gen_ndr/cli_winreg.c +++ b/librpc/gen_ndr/cli_winreg.c @@ -544,7 +544,7 @@ NTSTATUS rpccli_winreg_EnumValue(struct rpc_pipe_client *cli, *type = *r.out.type; } if (value && r.out.value) { - memcpy(value, r.out.value, *r.in.size * sizeof(*value)); + memcpy(value, r.out.value, (*r.in.size) * sizeof(*value)); } if (size && r.out.size) { *size = *r.out.size; @@ -915,7 +915,7 @@ NTSTATUS rpccli_winreg_QueryValue(struct rpc_pipe_client *cli, *type = *r.out.type; } if (data && r.out.data) { - memcpy(data, r.out.data, *r.in.data_size * sizeof(*data)); + memcpy(data, r.out.data, (*r.in.data_size) * sizeof(*data)); } if (data_size && r.out.data_size) { *data_size = *r.out.data_size; @@ -1481,9 +1481,9 @@ NTSTATUS rpccli_winreg_QueryMultipleValues(struct rpc_pipe_client *cli, } /* Return variables */ - memcpy(values, r.out.values, r.in.num_values * sizeof(*values)); + memcpy(values, r.out.values, (r.in.num_values) * sizeof(*values)); if (buffer && r.out.buffer) { - memcpy(buffer, r.out.buffer, *r.in.buffer_size * sizeof(*buffer)); + memcpy(buffer, r.out.buffer, (*r.in.buffer_size) * sizeof(*buffer)); } *buffer_size = *r.out.buffer_size; diff --git a/librpc/gen_ndr/ndr_winreg.c b/librpc/gen_ndr/ndr_winreg.c index fe76bca..2433ba0 100644 --- a/librpc/gen_ndr/ndr_winreg.c +++ b/librpc/gen_ndr/ndr_winreg.c @@ -3700,7 +3700,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_winreg_QueryMultipleValues(struct ndr_pull * if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) { NDR_PULL_ALLOC_N(ndr, r->in.values, ndr_get_array_size(ndr, &r->in.values)); } - memcpy(r->out.values, r->in.values, ndr_get_array_size(ndr, &r->in.values) * sizeof(*r->in.values)); + memcpy(r->out.values, r->in.values, (ndr_get_array_size(ndr, &r->in.values)) * sizeof(*r->in.values)); _mem_save_values_1 = NDR_PULL_GET_MEM_CTX(ndr); NDR_PULL_SET_MEM_CTX(ndr, r->in.values, 0); for (cntr_values_1 = 0; cntr_values_1 < r->in.num_values; cntr_values_1++) { @@ -3762,7 +3762,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_winreg_QueryMultipleValues(struct ndr_pull * if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) { NDR_PULL_ALLOC_N(ndr, r->out.values, ndr_get_array_size(ndr, &r->out.values)); } - memcpy(r->out.values, r->in.values, ndr_get_array_size(ndr, &r->out.values) * sizeof(*r->in.values)); + memcpy(r->out.values, r->in.values, (ndr_get_array_size(ndr, &r->out.values)) * sizeof(*r->in.values)); _mem_save_values_1 = NDR_PULL_GET_MEM_CTX(ndr); NDR_PULL_SET_MEM_CTX(ndr, r->out.values, 0); for (cntr_values_1 = 0; cntr_values_1 < r->in.num_values; cntr_values_1++) { diff --git a/source3/librpc/gen_ndr/messaging.h b/source3/librpc/gen_ndr/messaging.h index 3324160..b212b50 100644 --- a/source3/librpc/gen_ndr/messaging.h +++ b/source3/librpc/gen_ndr/messaging.h @@ -2,6 +2,8 @@ #include +#include "libcli/util/ntstatus.h" + #ifndef _HEADER_messaging #define _HEADER_messaging diff --git a/source3/librpc/gen_ndr/notify.h b/source3/librpc/gen_ndr/notify.h index a5ec4a4..981a5b7 100644 --- a/source3/librpc/gen_ndr/notify.h +++ b/source3/librpc/gen_ndr/notify.h @@ -2,6 +2,8 @@ #include +#include "libcli/util/ntstatus.h" + #ifndef _HEADER_notify #define _HEADER_notify -- 1.6.5.2