ctdb-tools: Fix ctdb dumpmemory to avoid printing trailing NUL
authorMartin Schwenke <martin@meltin.net>
Thu, 11 Apr 2019 06:56:32 +0000 (16:56 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 7 May 2019 05:45:34 +0000 (05:45 +0000)
Fix ctdb rddumpmemory too.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13923

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tools/ctdb.c

index 8db0ec8e7667cfe8936b052f1d1ca1aa09bba193..3c61c542ec4778056b06796ec7a2d13c580a087a 100644 (file)
@@ -2450,8 +2450,8 @@ static int control_dumpmemory(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                return ret;
        }
 
-       n = write(1, mem_str, strlen(mem_str)+1);
-       if (n < 0 || n != strlen(mem_str)+1) {
+       n = write(1, mem_str, strlen(mem_str));
+       if (n < 0 || n != strlen(mem_str)) {
                fprintf(stderr, "Failed to write talloc summary\n");
                return 1;
        }
@@ -2462,10 +2462,12 @@ static int control_dumpmemory(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 static void dump_memory(uint64_t srvid, TDB_DATA data, void *private_data)
 {
        bool *done = (bool *)private_data;
+       size_t len;
        ssize_t n;
 
-       n = write(1, data.dptr, data.dsize);
-       if (n < 0 || n != data.dsize) {
+       len = strnlen((const char *)data.dptr, data.dsize);
+       n = write(1, data.dptr, len);
+       if (n < 0 || n != len) {
                fprintf(stderr, "Failed to write talloc summary\n");
        }