Running `test/xattr` sometimes fails. When it fails, there are strange characters at the end of the returned value: ``` $ for i in {1..10}; do ./xattr; done; Error: fgetxattr expected value: value2-a-lot-longer, returned value: value2-a-lot-longer�� Error: fgetxattr expected value: value2-a-lot-longer, returned value: value2-a-lot-longerg� Error: fgetxattr expected value: value2-a-lot-longer, returned value: value2-a-lot-longeri� Error: fgetxattr expected value: value2-a-lot-longer, returned value: value2-a-lot-longerp� Error: fgetxattr expected value: value2-a-lot-longer, returned value: value2-a-lot-longer�� Error: fgetxattr expected value: value2-a-lot-longer, returned value: value2-a-lot-longer"� Error: fgetxattr expected value: value2-a-lot-longer, returned value: value2-a-lot-longer�� Error: fgetxattr expected value: value2-a-lot-longer, returned value: value2-a-lot-longerQ� ``` Debugged it with valgrind, valgrind says: ``` ==59962== Conditional jump or move depends on uninitialised value(s) ==59962== at 0x4849C59: strlen (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==59962== by 0x1099E9: test_fxattr (xattr.c:213) ==59962== by 0x109391: main (xattr.c:416) ``` It turned out that `char value[XATTR_SIZE]` may not be NUL terminated, so the `strlen()` results in the wrong value and %s format to the "returned value" shows strange characters. Fix this by changing it to `char value[XATTR_SIZE + 1] = { }` so that it is guaranteed to be NUL terminated. Cc: Stefan Roesch <shr@xxxxxx> Fixes: e194e24ff8721e67d8526737aa644b313bff3148 ("liburing: Add new test program to verify xattr support") Signed-off-by: Ammar Faizi <ammarfaizi2@xxxxxxxxx> --- test/xattr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/xattr.c b/test/xattr.c index d88059c..af7df5f 100644 --- a/test/xattr.c +++ b/test/xattr.c @@ -175,7 +175,7 @@ static int test_fxattr(void) int rc = 0; size_t value_len; struct io_uring ring; - char value[XATTR_SIZE]; + char value[XATTR_SIZE + 1] = { }; /* Init io-uring queue. */ int ret = io_uring_queue_init(QUEUE_DEPTH, &ring, 0); @@ -239,7 +239,7 @@ static int test_xattr(void) int rc = 0; int value_len; struct io_uring ring; - char value[XATTR_SIZE]; + char value[XATTR_SIZE + 1] = { }; /* Init io-uring queue. */ int ret = io_uring_queue_init(QUEUE_DEPTH, &ring, 0); @@ -292,7 +292,7 @@ static int test_failure_fxattr(void) { int rc = 0; struct io_uring ring; - char value[XATTR_SIZE]; + char value[XATTR_SIZE + 1] = { }; /* Init io-uring queue. */ int ret = io_uring_queue_init(QUEUE_DEPTH, &ring, 0); @@ -335,7 +335,7 @@ static int test_failure_xattr(void) { int rc = 0; struct io_uring ring; - char value[XATTR_SIZE]; + char value[XATTR_SIZE + 1] = { }; /* Init io-uring queue. */ int ret = io_uring_queue_init(QUEUE_DEPTH, &ring, 0); -- 2.32.0