[systemd-devel] [PATCH 1/2] kdbus: add kdbus_item_validate_name() to validate names

Djalal Harouni tixxdz at opendz.org
Mon Mar 17 03:53:57 PDT 2014


Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
---
 util.c | 22 ++++++++++++++++++++++
 util.h |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/util.c b/util.c
index 6dbcd8d..2e13f7c 100644
--- a/util.c
+++ b/util.c
@@ -14,6 +14,7 @@
 #include <linux/string.h>
 
 #include "util.h"
+#include "defaults.h"
 
 /**
  * kdbus_sysname_valid() - validate names showing up in /proc, /sys and /dev
@@ -45,3 +46,24 @@ int kdbus_sysname_is_valid(const char *name)
 
 	return 0;
 }
+
+/**
+ * kdbus_item_validate_name() - validate an item containing a name
+ * @item:		Item to validate
+ *
+ * Return: zero on success or an negative error code on failure
+ */
+int kdbus_item_validate_name(const struct kdbus_item *item)
+{
+	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;
+
+	return kdbus_sysname_is_valid(item->str);
+}
diff --git a/util.h b/util.h
index c8f44aa..06290fc 100644
--- a/util.h
+++ b/util.h
@@ -113,4 +113,6 @@ static inline unsigned int kdbus_str_hash(const char *str)
 }
 
 int kdbus_sysname_is_valid(const char *name);
+
+int kdbus_item_validate_name(const struct kdbus_item *item);
 #endif
-- 
1.8.5.3



More information about the systemd-devel mailing list