Use kdbus_item_validate_name() where appropriate. Signed-off-by: Djalal Harouni <tix...@opendz.org> --- bus.c | 11 +---------- connection.c | 9 +-------- domain.c | 15 +-------------- endpoint.c | 12 +----------- handle.c | 18 +----------------- 5 files changed, 5 insertions(+), 60 deletions(-)
diff --git a/bus.c b/bus.c index 1f72af5..d9bb81d 100644 --- a/bus.c +++ b/bus.c @@ -351,16 +351,7 @@ int kdbus_bus_make_user(const struct kdbus_cmd_make *make, if (n) return -EEXIST; - if (payload_size < 2) - return -EINVAL; - - if (payload_size > KDBUS_SYSNAME_MAX_LEN + 1) - return -ENAMETOOLONG; - - if (!kdbus_item_validate_nul(item)) - return -EINVAL; - - ret = kdbus_sysname_is_valid(item->str); + ret = kdbus_item_validate_name(item); if (ret < 0) return ret; diff --git a/connection.c b/connection.c index cef4421..55e567c 100644 --- a/connection.c +++ b/connection.c @@ -1934,14 +1934,7 @@ int kdbus_conn_new(struct kdbus_ep *ep, if (conn_name) return -EINVAL; - if (item->size > KDBUS_SYSNAME_MAX_LEN + - KDBUS_ITEM_HEADER_SIZE + 1) - return -ENAMETOOLONG; - - if (!kdbus_item_validate_nul(item)) - return -EINVAL; - - ret = kdbus_sysname_is_valid(item->str); + ret = kdbus_item_validate_name(item); if (ret < 0) return ret; diff --git a/domain.c b/domain.c index b928188..2e05e90 100644 --- a/domain.c +++ b/domain.c @@ -367,29 +367,16 @@ int kdbus_domain_make_user(struct kdbus_cmd_make *cmd, char **name) int ret; KDBUS_ITEMS_FOREACH(item, cmd->items, KDBUS_ITEMS_SIZE(cmd, items)) { - size_t payload_size; - if (!KDBUS_ITEM_VALID(item, &cmd->items, KDBUS_ITEMS_SIZE(cmd, items))) return -EINVAL; - payload_size = item->size - KDBUS_ITEM_HEADER_SIZE; - switch (item->type) { case KDBUS_ITEM_MAKE_NAME: if (n) return -EEXIST; - if (payload_size < 2) - return -EINVAL; - - if (payload_size > KDBUS_SYSNAME_MAX_LEN + 1) - return -ENAMETOOLONG; - - if (!kdbus_item_validate_nul(item)) - return -EINVAL; - - ret = kdbus_sysname_is_valid(item->str); + ret = kdbus_item_validate_name(item); if (ret < 0) return ret; diff --git a/endpoint.c b/endpoint.c index 6bb9b16..3dc9b49 100644 --- a/endpoint.c +++ b/endpoint.c @@ -282,17 +282,7 @@ int kdbus_ep_make_user(const struct kdbus_cmd_make *make, char **name) if (n) return -EEXIST; - if (item->size < KDBUS_ITEM_HEADER_SIZE + 2) - return -EINVAL; - - if (item->size > KDBUS_ITEM_HEADER_SIZE + - KDBUS_SYSNAME_MAX_LEN + 1) - return -ENAMETOOLONG; - - if (!kdbus_item_validate_nul(item)) - return -EINVAL; - - ret = kdbus_sysname_is_valid(item->str); + ret = kdbus_item_validate_name(item); if (ret < 0) return ret; diff --git a/handle.c b/handle.c index 7f57aa5..e0eb609 100644 --- a/handle.c +++ b/handle.c @@ -263,23 +263,7 @@ static int kdbus_handle_memfd(void __user *buf) goto exit; } - if (item->size < KDBUS_ITEM_HEADER_SIZE + 2) { - ret = -EINVAL; - goto exit; - } - - if (item->size > KDBUS_ITEM_HEADER_SIZE + - KDBUS_SYSNAME_MAX_LEN + 1) { - ret = -ENAMETOOLONG; - goto exit; - } - - if (!kdbus_item_validate_nul(item)) { - ret = -EINVAL; - goto exit; - } - - ret = kdbus_sysname_is_valid(item->str); + ret = kdbus_item_validate_name(item); if (ret < 0) goto exit; -- 1.8.5.3 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel