[systemd-commits] src/libsystemd-network

Tom Gundersen tomegun at kemper.freedesktop.org
Tue May 19 09:00:35 PDT 2015


 src/libsystemd-network/dhcp-identifier.c |    9 +++++----
 src/libsystemd-network/dhcp-identifier.h |    3 ++-
 2 files changed, 7 insertions(+), 5 deletions(-)

New commits:
commit 9ee18af3a036074c4021c82ae2e67f5ccaa9ea9d
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue May 19 17:47:19 2015 +0200

    dhcp-identifier: fix for unaligned write
    
    Reported by Michael Olbrich.

diff --git a/src/libsystemd-network/dhcp-identifier.c b/src/libsystemd-network/dhcp-identifier.c
index f7a1492..70c68ad 100644
--- a/src/libsystemd-network/dhcp-identifier.c
+++ b/src/libsystemd-network/dhcp-identifier.c
@@ -46,8 +46,9 @@ int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len) {
         if (r < 0)
                 return r;
 
-        duid->type = htobe16(DHCP6_DUID_EN);
-        duid->en.pen = htobe32(SYSTEMD_PEN);
+        unaligned_write_be16(&duid->type, DHCP6_DUID_EN);
+        unaligned_write_be32(&duid->en.pen, SYSTEMD_PEN);
+
         *len = sizeof(duid->type) + sizeof(duid->en);
 
         /* a bit of snake-oil perhaps, but no need to expose the machine-id
@@ -58,7 +59,7 @@ int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len) {
 }
 
 
-int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, uint32_t *_id) {
+int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_id) {
         /* name is a pointer to memory in the udev_device struct, so must
            have the same scope */
         _cleanup_udev_device_unref_ struct udev_device *device = NULL;
@@ -92,7 +93,7 @@ int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, uint32_t
                 siphash24((uint8_t*)&id, mac, mac_len, HASH_KEY.bytes);
 
         /* fold into 32 bits */
-        *_id = (id & 0xffffffff) ^ (id >> 32);
+        unaligned_write_be32(_id, (id & 0xffffffff) ^ (id >> 32));
 
         return 0;
 }
diff --git a/src/libsystemd-network/dhcp-identifier.h b/src/libsystemd-network/dhcp-identifier.h
index 643d497..9511791 100644
--- a/src/libsystemd-network/dhcp-identifier.h
+++ b/src/libsystemd-network/dhcp-identifier.h
@@ -24,6 +24,7 @@
 
 #include "macro.h"
 #include "sparse-endian.h"
+#include "unaligned.h"
 #include "sd-id128.h"
 
 /* RFC 3315 section 9.1:
@@ -61,4 +62,4 @@ struct duid {
 } _packed_;
 
 int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len);
-int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, uint32_t *_id);
+int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_id);



More information about the systemd-commits mailing list