[SCM] Samba Shared Repository - sizof(enum) == sizeof(int)

Andreas Schneider asn at samba.org
Tue Aug 17 04:54:13 MDT 2010


On Tuesday 17 August 2010 11:52:40 you wrote:
> On Tue, Aug 17, 2010 at 04:45:22AM -0500, Andreas Schneider wrote:
> >  	types.count = num_rids;
> > 
> > -	types.ids = type;
> > +	types.ids = (uint32_t *) type;
> 
> This looks wrong. AFAIK sizeof(enum)==sizeof(int). What
> happens on 64-bit machines?

I think you're right. It depends of the initialization of the enum, the 
compiler and of the compile options you use.

enum lsa_SidType {
 SID_NAME_USE_NONE=(int)(0),
 ...
}

is probably an unsigned int. If it would start with -1 it would be int. Unless 
you use --short-enums with gcc. So you can't be sure that enum is always an 
int.

diff --git a/source3/rpc_server/srv_samr_nt.c 
b/source3/rpc_server/srv_samr_nt.c
index a19be4e..8075227 100644
--- a/source3/rpc_server/srv_samr_nt.c
+++ b/source3/rpc_server/srv_samr_nt.c
@@ -1795,7 +1795,11 @@ NTSTATUS _samr_LookupNames(struct pipes_struct *p,
        rids.ids = rid;
 
        types.count = num_rids;
-       types.ids = (uint32_t *) type;
+       types.ids = talloc_array(p->mem_ctx, uint32_t, num_rids);
+       NT_STATUS_HAVE_NO_MEMORY(type);
+       for (i = 0; i < num_rids; i++) {
+               types.ids[i] = (uint32_t) (type[i] & 0xffffffff);
+       }
 
        *r->out.rids = rids;
        *r->out.types = types;


	-- andreas



More information about the samba-technical mailing list