tests: strncpy() corrections
authorDaniel Mack <daniel@zonque.org>
Tue, 14 Oct 2014 12:54:27 +0000 (14:54 +0200)
committerDaniel Mack <daniel@zonque.org>
Tue, 14 Oct 2014 12:56:32 +0000 (14:56 +0200)
Use the correct maximum size with strncpy(), even though we're using
small static strings as sources.

Signed-off-by: Daniel Mack <daniel@zonque.org>
test/test-endpoint.c
test/test-match.c
tools/kdbus-monitor.c

index 390a65b0db73bd3ee2b8e1795384aca7cfd17884..0aab4d4e791a6f185406f40429bd7f3697333ad7 100644 (file)
@@ -106,7 +106,7 @@ static int update_endpoint(int fd, const char *name)
 
        ep_update.name.size = KDBUS_ITEM_HEADER_SIZE + len;
        ep_update.name.type = KDBUS_ITEM_NAME;
-       strncpy(ep_update.name.str, name, sizeof(ep_update.name.str));
+       strncpy(ep_update.name.str, name, sizeof(ep_update.name.str) - 1);
 
        ep_update.access.size = sizeof(ep_update.access);
        ep_update.access.type = KDBUS_ITEM_POLICY_ACCESS;
index b3a869aa073072db421d9c89798f0ec33f8b4118..8cc6b1665e4a77afeb7f0b2dd0934d173c452843 100644 (file)
@@ -122,7 +122,7 @@ int kdbus_test_match_name_add(struct kdbus_test_env *env)
        buf.item.type = KDBUS_ITEM_NAME_ADD;
        buf.item.chg.old_id.id = KDBUS_MATCH_ID_ANY;
        buf.item.chg.new_id.id = KDBUS_MATCH_ID_ANY;
-       strncpy(buf.name, name, sizeof(buf.name));
+       strncpy(buf.name, name, sizeof(buf.name) - 1);
        buf.item.size = sizeof(buf.item) + strlen(buf.name) + 1;
        buf.cmd.size = sizeof(buf.cmd) + buf.item.size;
 
@@ -171,7 +171,7 @@ int kdbus_test_match_name_remove(struct kdbus_test_env *env)
        buf.item.type = KDBUS_ITEM_NAME_REMOVE;
        buf.item.chg.old_id.id = KDBUS_MATCH_ID_ANY;
        buf.item.chg.new_id.id = KDBUS_MATCH_ID_ANY;
-       strncpy(buf.name, name, sizeof(buf.name));
+       strncpy(buf.name, name, sizeof(buf.name) - 1);
        buf.item.size = sizeof(buf.item) + strlen(buf.name) + 1;
        buf.cmd.size = sizeof(buf.cmd) + buf.item.size;
 
@@ -220,7 +220,7 @@ int kdbus_test_match_name_change(struct kdbus_test_env *env)
        buf.item.type = KDBUS_ITEM_NAME_CHANGE;
        buf.item.chg.old_id.id = KDBUS_MATCH_ID_ANY;
        buf.item.chg.new_id.id = KDBUS_MATCH_ID_ANY;
-       strncpy(buf.name, name, sizeof(buf.name));
+       strncpy(buf.name, name, sizeof(buf.name) - 1);
        buf.item.size = sizeof(buf.item) + strlen(buf.name) + 1;
        buf.cmd.size = sizeof(buf.cmd) + buf.item.size;
 
index 87bac686e3119db5e5edabb2fe6c9850246a2024..4bb61b70f869c99bf67c367eb9a4a037c0e02482 100644 (file)
@@ -84,7 +84,7 @@ static struct conn *kdbus_hello(const char *path, uint64_t flags)
        h.hello.conn_flags = flags | KDBUS_HELLO_ACCEPT_FD;
        h.hello.attach_flags = _KDBUS_ATTACH_ALL;
        h.type = KDBUS_ITEM_CONN_NAME;
-       strncpy(h.comm, "monitor", sizeof(h.comm));
+       strncpy(h.comm, "monitor", sizeof(h.comm) - 1);
        h.size = KDBUS_ITEM_HEADER_SIZE + strlen(h.comm) + 1;
 
        h.hello.size = sizeof(h);