From: Daniel Mack Date: Tue, 14 Oct 2014 12:54:27 +0000 (+0200) Subject: tests: strncpy() corrections X-Git-Tag: upstream/0.20141102.012929utc~99 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b29abaa5ccea0025b837a78444d06377d8bcfc4d;p=platform%2Fcore%2Fsystem%2Fkdbus-bus.git tests: strncpy() corrections Use the correct maximum size with strncpy(), even though we're using small static strings as sources. Signed-off-by: Daniel Mack --- diff --git a/test/test-endpoint.c b/test/test-endpoint.c index 390a65b..0aab4d4 100644 --- a/test/test-endpoint.c +++ b/test/test-endpoint.c @@ -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; diff --git a/test/test-match.c b/test/test-match.c index b3a869a..8cc6b16 100644 --- a/test/test-match.c +++ b/test/test-match.c @@ -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; diff --git a/tools/kdbus-monitor.c b/tools/kdbus-monitor.c index 87bac68..4bb61b7 100644 --- a/tools/kdbus-monitor.c +++ b/tools/kdbus-monitor.c @@ -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);