[systemd-devel] [PATCH] test-kdbus: fixed unterminated string

Jacek Janczyk j.janczyk at samsung.com
Mon May 12 06:35:08 PDT 2014


Unterminated string array is used to populate random bus name
in check_prepare_env(). Added proper termination.

Signed-off-by: Jacek Janczyk <j.janczyk at samsung.com>
---
 test/test-kdbus.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/test/test-kdbus.c b/test/test-kdbus.c
index e369b4e..f0bf705 100644
--- a/test/test-kdbus.c
+++ b/test/test-kdbus.c
@@ -1042,7 +1042,7 @@ static int check_prepare_env(const struct kdbus_check *c, struct kdbus_check_env
 			char name[64];
 		} bus_make;
 		unsigned int i;
-		char n[32];
+		char n[32 + 1];
 		int ret;
 
 		env->control_fd = open("/dev/" KBUILD_MODNAME "/control", O_RDWR|O_CLOEXEC);
@@ -1054,8 +1054,9 @@ static int check_prepare_env(const struct kdbus_check *c, struct kdbus_check_env
 		bus_make.bs.bloom.size = 64;
 		bus_make.bs.bloom.n_hash = 1;
 
-		for (i = 0; i < sizeof(n); i++)
+		for (i = 0; i < sizeof(n) - 1; i++)
 			n[i] = 'a' + (random() % ('z' - 'a'));
+		n[sizeof(n) - 1] = 0;
 
 		snprintf(bus_make.name, sizeof(bus_make.name), "%u-%s", getuid(), n);
 
-- 
1.7.9.5



More information about the systemd-devel mailing list