summaryrefslogtreecommitdiff
path: root/ctdb/protocol/protocol_types.c
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2017-07-06 14:25:58 +1000
committerMartin Schwenke <martins@samba.org>2017-08-30 14:59:24 +0200
commit85d0825f2106f7e6a01d592df19bec91a95f0ec5 (patch)
tree0572c38eb645a7eba1b0d61d46d8bf867d1c80d8 /ctdb/protocol/protocol_types.c
parentc060d01b3fe44b80125454d2ead8b040e7f3329c (diff)
downloadsamba-85d0825f2106f7e6a01d592df19bec91a95f0ec5.tar.gz
ctdb-protocol: Fix marshalling for ctdb_node_map
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb/protocol/protocol_types.c')
-rw-r--r--ctdb/protocol/protocol_types.c101
1 files changed, 50 insertions, 51 deletions
diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c
index 818d805d6d8..c98e0d922c8 100644
--- a/ctdb/protocol/protocol_types.c
+++ b/ctdb/protocol/protocol_types.c
@@ -3610,84 +3610,83 @@ int ctdb_node_and_flags_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
return ret;
}
-struct ctdb_node_map_wire {
- uint32_t num;
- struct ctdb_node_and_flags node[1];
-};
-
-size_t ctdb_node_map_len(struct ctdb_node_map *nodemap)
+size_t ctdb_node_map_len(struct ctdb_node_map *in)
{
- return sizeof(uint32_t) +
- nodemap->num * sizeof(struct ctdb_node_and_flags);
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_node_and_flags_len(&in->node[0]);
+ }
+
+ return len;
}
-void ctdb_node_map_push(struct ctdb_node_map *nodemap, uint8_t *buf)
+void ctdb_node_map_push(struct ctdb_node_map *in, uint8_t *buf, size_t *npush)
{
- struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf;
- size_t offset, np;
- int i;
+ size_t offset = 0, np;
+ uint32_t i;
- wire->num = nodemap->num;
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
- offset = offsetof(struct ctdb_node_map_wire, node);
- for (i=0; i<nodemap->num; i++) {
- ctdb_node_and_flags_push(&nodemap->node[i], &buf[offset], &np);
+ for (i=0; i<in->num; i++) {
+ ctdb_node_and_flags_push(&in->node[i], buf+offset, &np);
offset += np;
}
+
+ *npush = offset;
}
int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_node_map **out)
+ struct ctdb_node_map **out, size_t *npull)
{
- struct ctdb_node_map *nodemap;
- struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf;
- size_t offset, np;
- int i;
- bool ret;
+ struct ctdb_node_map *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
- if (buflen < sizeof(uint32_t)) {
- return EMSGSIZE;
- }
- if (wire->num > buflen / sizeof(struct ctdb_node_and_flags)) {
- return EMSGSIZE;
- }
- if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_node_and_flags) <
- sizeof(uint32_t)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_node_map);
+ if (val == NULL) {
+ return ENOMEM;
}
- if (buflen < sizeof(uint32_t) +
- wire->num * sizeof(struct ctdb_node_and_flags)) {
- return EMSGSIZE;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- nodemap = talloc(mem_ctx, struct ctdb_node_map);
- if (nodemap == NULL) {
- return ENOMEM;
+ if (val->num == 0) {
+ val->node = NULL;
+ goto done;
}
- nodemap->num = wire->num;
- nodemap->node = talloc_array(nodemap, struct ctdb_node_and_flags,
- wire->num);
- if (nodemap->node == NULL) {
- talloc_free(nodemap);
- return ENOMEM;
+ val->node = talloc_array(val, struct ctdb_node_and_flags, val->num);
+ if (val->node == NULL) {
+ ret = ENOMEM;
+ goto fail;
}
- offset = offsetof(struct ctdb_node_map_wire, node);
- for (i=0; i<wire->num; i++) {
- ret = ctdb_node_and_flags_pull_elems(&buf[offset],
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_node_and_flags_pull_elems(buf+offset,
buflen-offset,
- nodemap->node,
- &nodemap->node[i], &np);
+ val->node, &val->node[i],
+ &np);
if (ret != 0) {
- talloc_free(nodemap);
- return ret;
+ goto fail;
}
offset += np;
}
- *out = nodemap;
+done:
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
size_t ctdb_script_len(struct ctdb_script *script)