[klibc] [klibc:master] ipconfig: Fix alignment of packet structure

klibc-bot for Ben Hutchings ben at decadent.org.uk
Sat Mar 28 15:36:02 PDT 2020


Commit-ID:  7ffa5f8d889e8107fd97fcc5628f87e6ef2f4b91
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=7ffa5f8d889e8107fd97fcc5628f87e6ef2f4b91
Author:     Ben Hutchings <ben at decadent.org.uk>
AuthorDate: Sat, 28 Mar 2020 22:07:00 +0000
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 28 Mar 2020 22:18:56 +0000

[klibc] ipconfig: Fix alignment of packet structure

This structure should have alignment of exactly 4, since we want the
16-bit and 32-bit fields in it to have natural alignment but we don't
want extra padding that would violate the wire protocols.

This should be what happens by default, but for some reason it's
declared with the "packed" attribute.  gcc is now warning about using
potentially misaligned pointers to its members.

Add the attribute "aligned(4)" so that it is definitely exactly 4-byte
aligned.

Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/kinit/ipconfig/packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr/kinit/ipconfig/packet.c b/usr/kinit/ipconfig/packet.c
index 20018010..2e1487d2 100644
--- a/usr/kinit/ipconfig/packet.c
+++ b/usr/kinit/ipconfig/packet.c
@@ -86,7 +86,7 @@ static unsigned int ip_checksum(uint16_t *hdr, int len)
 struct header {
 	struct iphdr ip;
 	struct udphdr udp;
-} __attribute__ ((packed));
+} __attribute__ ((packed, aligned(4)));
 
 static struct header ipudp_hdrs = {
 	.ip = {


More information about the klibc mailing list