libnetfilter-conntrack byte alignment
PATCH 3/3 libnetfilter-conntrack byte alignment
Aligns buffers to maximum alignment of architecture to make the cast of char pointers to struct pointers more portable.
Signed-off-by Fabian Hugelshofer <[email protected]>
src/conntrack/api.c +1 -1
@@ -561,7 +561,7 @@ const void *data) {size_t size =4096 ;/* enough for now */ -char buffer[4096 ]; + char buffer[4096] __attribute__ ((aligned));struct nfnlhdr *req = (struct nfnlhdr *) buffer;assert (h !=NULL );
src/expect/api.c +1 -1
@@ -507,7 +507,7 @@ const void *data) {size_t size =4096 ;/* enough for now */ -char buffer[4096 ]; + char buffer[4096] __attribute__ ((aligned));struct nfnlhdr *req = (struct nfnlhdr *) buffer;assert (h !=NULL );
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Use union of char buffer and message header to ensure proper byte alignment.
Signed-off-by Fabian Hugelshofer <[email protected]>
src/conntrack/api.c +12 -8
@@ -563,16 +563,18 @@ int nfct_query(struct nfct_handle *h, const void *data) {size_t size =4096 ;/* enough for now */ -char buffer[4096 ]; -struct nfnlhdr *req = (struct nfnlhdr *) buffer; +union { +char buffer[size]; +struct nfnlhdr req; + } u;assert (h !=NULL );assert (data !=NULL ); -if (nfct_build_query (h->nfnlssh_ct, qt, data, req, size) ==-1 ) +if (nfct_build_query (h->nfnlssh_ct, qt, data, &u.req, size) ==-1 )return -1 ; -return nfnl_query (h->nfnlh, &req->nlh); +return nfnl_query (h->nfnlh, &u.req.nlh); }/**
@@ -593,16 +595,18 @@ int nfct_send(struct nfct_handle *h, const void *data) {size_t size =4096 ;/* enough for now */ -char buffer[4096 ]; -struct nfnlhdr *req = (struct nfnlhdr *) buffer; +union { +char buffer[size]; +struct nfnlhdr req; + } u;assert (h !=NULL );assert (data !=NULL ); -if (nfct_build_query (h->nfnlssh_ct, qt, data, req, size) ==-1 ) +if (nfct_build_query (h->nfnlssh_ct, qt, data, &u.req, size) ==-1 )return -1 ; -return nfnl_send (h->nfnlh, &req->nlh); +return nfnl_send (h->nfnlh, &u.req.nlh); }
src/expect/api.c +6 -4
@@ -507,16 +507,18 @@ int nfexp_query(struct nfct_handle *h, const void *data) {size_t size =4096 ;/* enough for now */ -char buffer[4096 ]; -struct nfnlhdr *req = (struct nfnlhdr *) buffer; +union { +char buffer[size]; +struct nfnlhdr req; + } u;assert (h !=NULL );assert (data !=NULL ); -if (nfexp_build_query (h->nfnlssh_exp, qt, data, req, size) ==-1 ) +if (nfexp_build_query (h->nfnlssh_exp, qt, data, &u.req, size) ==-1 )return -1 ; -return nfnl_query (h->nfnlh, &req->nlh); +return nfnl_query (h->nfnlh, &u.req.nlh); }/**
Pablo Neira Ayuso
maintainerQuoted 2 lines · Fabian Hugelshofer
Use union of char buffer and message header to ensure proper byte alignment.
Also applied. Thanks.
Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers