chiark / gitweb /
bus: add missing LE meta data enforcement for gvariant serializer
authorLennart Poettering <lennart@poettering.net>
Thu, 5 Dec 2013 02:09:09 +0000 (03:09 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 5 Dec 2013 02:09:09 +0000 (03:09 +0100)
src/libsystemd-bus/bus-message.c
src/libsystemd-bus/test-bus-gvariant.c

index 73b0bab..4c0e27f 100644 (file)
@@ -1912,7 +1912,7 @@ static int bus_message_close_array(sd_bus_message *m, struct bus_container *c) {
                                 return -ENOMEM;
 
                         for (i = 0; i < c->n_offsets; i++) {
-                                uint16_t x = (uint16_t) (c->offsets[i] - c->begin);
+                                uint16_t x = htole16((uint16_t) (c->offsets[i] - c->begin));
                                 memcpy(a + (i*2), &x, 2);
                         }
 
@@ -1922,7 +1922,7 @@ static int bus_message_close_array(sd_bus_message *m, struct bus_container *c) {
                                 return -ENOMEM;
 
                         for (i = 0; i < c->n_offsets; i++) {
-                                uint32_t x = (uint32_t) (c->offsets[i] - c->begin);
+                                uint32_t x = htole32((uint32_t) (c->offsets[i] - c->begin));
                                 memcpy(a + (i*4), &x, 4);
                         }
                 } else {
@@ -1931,7 +1931,7 @@ static int bus_message_close_array(sd_bus_message *m, struct bus_container *c) {
                                 return -ENOMEM;
 
                         for (i = 0; i < c->n_offsets; i++) {
-                                uint64_t x = (uint64_t) (c->offsets[i] - c->begin);
+                                uint64_t x = htole64((uint64_t) (c->offsets[i] - c->begin));
                                 memcpy(a + (i*8), &x, 8);
                         }
                 }
@@ -2054,13 +2054,13 @@ static int bus_message_close_struct(sd_bus_message *m, struct bus_container *c,
                         if (z == 1)
                                 ((uint8_t*) a)[k] = (uint8_t) v;
                         else if (z == 2) {
-                                uint16_t x = (uint16_t) v;
+                                uint16_t x = htole16((uint16_t) v);
                                 memcpy(a + k * 2, &x, 2);
                         } else if (z == 4) {
-                                uint32_t x = (uint32_t) v;
+                                uint32_t x = htole32((uint32_t) v);
                                 memcpy(a + k * 4, &x, 4);
                         } else if (z == 8) {
-                                uint64_t x = (uint64_t) v;
+                                uint64_t x = htole64((uint64_t) v);
                                 memcpy(a + k * 8, &x, 8);
                         } else
                                 assert_not_reached("Wrong offset width");
@@ -4392,13 +4392,13 @@ static int bus_message_close_header(sd_bus_message *m) {
                 if (z == 1)
                         ((uint8_t*) a)[i] = (uint8_t) m->header_offsets[i];
                 else if (z == 2) {
-                        uint16_t x = (uint16_t) m->header_offsets[i];
+                        uint16_t x = htole16((uint16_t) m->header_offsets[i]);
                         memcpy(a + 2*i, &x, 2);
                 } else if (z == 4) {
-                        uint32_t x = (uint32_t) m->header_offsets[i];
+                        uint32_t x = htole32((uint32_t) m->header_offsets[i]);
                         memcpy(a + 4*i, &x, 4);
                 } else if (z == 8) {
-                        uint64_t x = (uint64_t) m->header_offsets[i];
+                        uint64_t x = htole64((uint64_t) m->header_offsets[i]);
                         memcpy(a + 8*i, &x, 8);
                 } else
                         assert_not_reached("unknown type");
index a5f8a17..9888e33 100644 (file)
@@ -89,7 +89,7 @@ static void test_marshal(void) {
         assert_se(sd_bus_open_system(&bus) >= 0);
         bus->use_gvariant = true; /* dirty hack */
 
-        assert_se(sd_bus_message_new_method_call(bus, "a.service.name", "/an/object/path", "an.interface.name", "AMethodName", &m) >= 0);
+        assert_se(sd_bus_message_new_method_call(bus, "a.service.name", "/an/object/path/which/is/really/really/long/so/that/we/hit/the/eight/bit/boundary/by/quite/some/margin/to/test/this/stuff/that/it/really/works", "an.interface.name", "AMethodName", &m) >= 0);
 
         /* assert_se(sd_bus_message_append(m, "ssy(sts)v", "first-string-parameter", "second-string-parameter", 9, "a", (uint64_t) 7777, "b", "(su)", "xxx", 4712) >= 0);  */
         assert_se(sd_bus_message_append(m,