]> granicus.if.org Git - ipset/commitdiff
Handle uint64_t alignment issue in ipset tool
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Wed, 28 Oct 2015 16:13:31 +0000 (17:13 +0100)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Wed, 28 Oct 2015 16:13:31 +0000 (17:13 +0100)
lib/debug.c
lib/session.c

index b2c5003d3b7d18b2a11b1694b3e9a00655c40110..6f831ecccf55e9b9d0f73e4e94a184935e6d0874 100644 (file)
@@ -77,6 +77,7 @@ debug_cadt_attrs(int max, const struct ipset_attr_policy *policy,
                 const struct ipset_attrname attr2name[],
                 struct nlattr *nla[])
 {
+       uint64_t tmp;
        uint32_t v;
        int i;
 
@@ -102,10 +103,10 @@ debug_cadt_attrs(int max, const struct ipset_attr_policy *policy,
                                attr2name[i].name, ntohl(v));
                        break;
                case MNL_TYPE_U64:
+                       memcpy(&tmp, mnl_attr_get_payload(nla[i]), sizeof(tmp));
                        fprintf(stderr, "\t\t%s: 0x%llx\n",
                                attr2name[i].name, (long long int)
-                               be64toh(*(uint64_t *)
-                                       mnl_attr_get_payload(nla[i])));
+                               be64toh(tmp));
                        break;
                case MNL_TYPE_NUL_STRING:
                        fprintf(stderr, "\t\t%s: %s\n",
index 95c253ecd71e7d6f385240f208767a8c83e3f496..24f29f592ed8c6af41f084807bbd61a6246d6939 100644 (file)
@@ -636,7 +636,10 @@ attr2data(struct ipset_session *session, struct nlattr *nla[],
                D("netorder attr type %u", type);
                switch (attr->type) {
                case MNL_TYPE_U64: {
-                       v64  = be64toh(*(const uint64_t *)d);
+                       uint64_t tmp;
+                       /* Ensure data alignment */
+                       memcpy(&tmp, d, sizeof(tmp));
+                       v64  = be64toh(tmp);
                        d = &v64;
                        break;
                }