chiark / gitweb /
bus: generate a nice error when attempting to add a NULL string
[elogind.git] / src / libsystemd-bus / bus-message.c
index c385ef5..524f17e 100644 (file)
@@ -403,6 +403,8 @@ static int message_new_reply(
 
         if (!call)
                 return -EINVAL;
+        if (!call->sealed)
+                return -EPERM;
         if (call->header->type != SD_BUS_MESSAGE_TYPE_METHOD_CALL)
                 return -EINVAL;
         if (!m)
@@ -766,11 +768,27 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
 
         case SD_BUS_TYPE_STRING:
         case SD_BUS_TYPE_OBJECT_PATH:
+
+                if (!p) {
+                        if (e)
+                                c->signature[c->index] = 0;
+
+                        return -EINVAL;
+                }
+
                 align = 4;
                 sz = 4 + strlen(p) + 1;
                 break;
 
         case SD_BUS_TYPE_SIGNATURE:
+
+                if (!p) {
+                        if (e)
+                                c->signature[c->index] = 0;
+
+                        return -EINVAL;
+                }
+
                 align = 1;
                 sz = 1 + strlen(p) + 1;
                 break;
@@ -2213,8 +2231,8 @@ static int message_skip_fields(
                 } else if (bus_type_is_basic(t)) {
                         size_t align, k;
 
-                        align = bus_type_get_alignment(align);
-                        k = bus_type_get_size(align);
+                        align = bus_type_get_alignment(t);
+                        k = bus_type_get_size(t);
 
                         r = message_peek_fields(m, ri, align, k, NULL);
                         if (r < 0)
@@ -2441,14 +2459,17 @@ static void setup_iovec(sd_bus_message *m) {
         assert(m->sealed);
 
         m->n_iovec = 0;
+        m->size = 0;
 
         m->iovec[m->n_iovec].iov_base = m->header;
         m->iovec[m->n_iovec].iov_len = sizeof(*m->header);
+        m->size += m->iovec[m->n_iovec].iov_len;
         m->n_iovec++;
 
         if (m->fields) {
                 m->iovec[m->n_iovec].iov_base = m->fields;
                 m->iovec[m->n_iovec].iov_len = m->header->fields_size;
+                m->size += m->iovec[m->n_iovec].iov_len;
                 m->n_iovec++;
 
                 if (m->header->fields_size % 8 != 0) {
@@ -2456,6 +2477,7 @@ static void setup_iovec(sd_bus_message *m) {
 
                         m->iovec[m->n_iovec].iov_base = (void*) padding;
                         m->iovec[m->n_iovec].iov_len = 8 - m->header->fields_size % 8;
+                        m->size += m->iovec[m->n_iovec].iov_len;
                         m->n_iovec++;
                 }
         }
@@ -2463,6 +2485,7 @@ static void setup_iovec(sd_bus_message *m) {
         if (m->body) {
                 m->iovec[m->n_iovec].iov_base = m->body;
                 m->iovec[m->n_iovec].iov_len = m->header->body_size;
+                m->size += m->iovec[m->n_iovec].iov_len;
                 m->n_iovec++;
         }
 }