diff --git a/include/lber.h b/include/lber.h index 77a32fa891..3b351c5818 100644 --- a/include/lber.h +++ b/include/lber.h @@ -158,6 +158,17 @@ extern char ber_pvt_opt_on; #define LBER_OPT_ERROR (-1) #define LBER_ELEMENT_SIZEOF (256) /* must be >= sizeof(BerElement) */ +typedef union ber_buffer_u { + char charbuf[LBER_ELEMENT_SIZEOF]; + + /* force alignment */ + int intbuf; + long longbuf; + float floatbuf; + double doublebuf; + char* ptrbuf; +} BerElementBuffer; + typedef struct berelement BerElement; typedef struct sockbuf Sockbuf; typedef struct seqorset Seqorset; diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index 80241ecd14..b1c7864fd2 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -83,8 +83,8 @@ int slap_passwd_parse( struct berval *reqdata, int rc = LDAP_SUCCESS; ber_tag_t tag; ber_len_t len; - char berbuf[LBER_ELEMENT_SIZEOF]; - BerElement *ber = (BerElement *)berbuf; + BerElementBuffer berbuf; + BerElement *ber = (BerElement *)&berbuf; if( reqdata == NULL ) { return LDAP_SUCCESS; @@ -224,9 +224,9 @@ struct berval * slap_passwd_return( { int rc; struct berval *bv = NULL; - char berbuf[LBER_ELEMENT_SIZEOF]; + BerElementBuffer berbuf; /* opaque structure, size unknown but smaller than berbuf */ - BerElement *ber = (BerElement *)berbuf; + BerElement *ber = (BerElement *)&berbuf; assert( cred != NULL ); diff --git a/servers/slapd/result.c b/servers/slapd/result.c index 08ddfda50f..3beff2f438 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -223,8 +223,8 @@ send_ldap_response( Operation *op, SlapReply *rs ) { - char berbuf[LBER_ELEMENT_SIZEOF]; - BerElement *ber = (BerElement *)berbuf; + BerElementBuffer berbuf; + BerElement *ber = (BerElement *) &berbuf; int rc; long bytes; @@ -602,8 +602,8 @@ slap_send_ldap_intermediate( Operation *op, SlapReply *rs ) int slap_send_search_entry( Operation *op, SlapReply *rs ) { - char berbuf[LBER_ELEMENT_SIZEOF]; - BerElement *ber = (BerElement *)berbuf; + BerElementBuffer berbuf; + BerElement *ber = (BerElement *) &berbuf; Attribute *a, *aa; int i, j, rc=-1, bytes; char *edn; @@ -1193,8 +1193,8 @@ error_return:; int slap_send_search_reference( Operation *op, SlapReply *rs ) { - char berbuf[LBER_ELEMENT_SIZEOF]; - BerElement *ber = (BerElement *)berbuf; + BerElementBuffer berbuf; + BerElement *ber = (BerElement *) &berbuf; int rc = 0; int bytes; void *mark; @@ -1437,8 +1437,8 @@ int slap_read_controls( { int rc; struct berval bv; - char berbuf[LBER_ELEMENT_SIZEOF]; - BerElement *ber = (BerElement *) berbuf; + BerElementBuffer berbuf; + BerElement *ber = (BerElement *) &berbuf; LDAPControl c; ber_len_t siz, len; Operation myop; diff --git a/servers/slapd/str2filter.c b/servers/slapd/str2filter.c index 310c3a56c9..0fc29bc22a 100644 --- a/servers/slapd/str2filter.c +++ b/servers/slapd/str2filter.c @@ -28,8 +28,8 @@ str2filter_x( Operation *op, const char *str ) { int rc; Filter *f = NULL; - char berbuf[LBER_ELEMENT_SIZEOF]; - BerElement *ber = (BerElement *)berbuf; + BerElementBuffer berbuf; + BerElement *ber = (BerElement *)&berbuf; const char *text = NULL; #ifdef NEW_LOGGING