tools/xenstore: avoid unterminated string in xs_directory_part()
authorJuergen Gross <jgross@suse.com>
Tue, 6 Dec 2016 06:41:54 +0000 (07:41 +0100)
committerWei Liu <wei.liu2@citrix.com>
Tue, 6 Dec 2016 11:59:37 +0000 (11:59 +0000)
Commit d4016288ab1f ("xenstore: support XS_DIRECTORY_PART in
libxenstore") introduced a theoretical bug: the generation count of
the read node is transferred via strncpy without forcing a NUL byte
at the end. Correct this.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/xenstore/xs.c

index e462a20f675f42ea827e404d1497ce3ca58ec2a8..3ce7157fed743967f3ed18100e3e7993e2141e1d 100644 (file)
@@ -589,7 +589,7 @@ static char **xs_directory_part(struct xs_handle *h, xs_transaction_t t,
        struct iovec iovec[2];
        char *result = NULL, *strings = NULL;
 
-       gen[0] = 0;
+       memset(gen, 0, sizeof(gen));
        iovec[0].iov_base = (void *)path;
        iovec[0].iov_len = strlen(path) + 1;
 
@@ -616,7 +616,7 @@ static char **xs_directory_part(struct xs_handle *h, xs_transaction_t t,
                                continue;
                        }
                } else
-                       strncpy(gen, result, sizeof(gen));
+                       strncpy(gen, result, sizeof(gen) - 1);
 
                result_len -= strlen(result) + 1;
                strings = realloc(strings, off + result_len);