diff options
author | Amitay Isaacs <amitay@gmail.com> | 2016-05-03 16:46:29 +1000 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2016-06-18 19:33:14 +0200 |
commit | e3e8ce4b81d617b50f91e238d4e93a5075735658 (patch) | |
tree | a5877725d2f3473560b4afac81c54668048c8802 /ctdb/protocol | |
parent | 747de99fcd70f400ec0ca6b2ca020664f7464454 (diff) | |
download | samba-e3e8ce4b81d617b50f91e238d4e93a5075735658.tar.gz |
ctdb-protocol: Fix marshaling of uint arrays
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'ctdb/protocol')
-rw-r--r-- | ctdb/protocol/protocol_types.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c index fa11bc2bcc2..d1890cf608e 100644 --- a/ctdb/protocol/protocol_types.c +++ b/ctdb/protocol/protocol_types.c @@ -97,7 +97,9 @@ size_t ctdb_uint8_array_len(struct ctdb_uint8_array *array) void ctdb_uint8_array_push(struct ctdb_uint8_array *array, uint8_t *buf) { - memcpy(buf, array->val, array->num * sizeof(uint8_t)); + if (array->num > 0) { + memcpy(buf, array->val, array->num * sizeof(uint8_t)); + } } int ctdb_uint8_array_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, @@ -112,12 +114,16 @@ int ctdb_uint8_array_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, array->num = buflen / sizeof(uint8_t); - array->val = talloc_array(array, uint8_t, array->num); - if (array->val == NULL) { - talloc_free(array); - return ENOMEM; + if (array->num > 0) { + array->val = talloc_array(array, uint8_t, array->num); + if (array->val == NULL) { + talloc_free(array); + return ENOMEM; + } + memcpy(array->val, buf, buflen); + } else { + array->val = NULL; } - memcpy(array->val, buf, buflen); *out = array; return 0; @@ -130,7 +136,9 @@ size_t ctdb_uint64_array_len(struct ctdb_uint64_array *array) void ctdb_uint64_array_push(struct ctdb_uint64_array *array, uint8_t *buf) { - memcpy(buf, array->val, array->num * sizeof(uint64_t)); + if (array->num > 0) { + memcpy(buf, array->val, array->num * sizeof(uint64_t)); + } } int ctdb_uint64_array_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, @@ -145,12 +153,16 @@ int ctdb_uint64_array_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, array->num = buflen / sizeof(uint64_t); - array->val = talloc_array(array, uint64_t, array->num); - if (array->val == NULL) { - talloc_free(array); - return ENOMEM; + if (array->num > 0) { + array->val = talloc_array(array, uint64_t, array->num); + if (array->val == NULL) { + talloc_free(array); + return ENOMEM; + } + memcpy(array->val, buf, buflen); + } else { + array->val = NULL; } - memcpy(array->val, buf, buflen); *out = array; return 0; |