summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2014-07-14 14:01:47 +0200
committerKeith Packard <keithp@keithp.com>2014-07-14 13:21:30 -0700
commit4dbb641bb2d4037f107b58b31e80963dc8b72c0e (patch)
treea9666f9a0a2dc41c4d21636dbf1cf0699b9bde60 /config
parent25eca7ce35973577c8d85704c270f7fb53e6732e (diff)
config_odev_add_attribute*: Check for right attribute type
Don't allow setting string attributes to integers and vice versa. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Keith Packard <keithp@keithp.com> Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'config')
-rw-r--r--config/config.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/config/config.c b/config/config.c
index 551451623..a26d835e1 100644
--- a/config/config.c
+++ b/config/config.c
@@ -172,12 +172,38 @@ config_odev_find_or_add_attribute(struct OdevAttributes *attribs, int attrib)
return oa;
}
+static int config_odev_get_attribute_type(int attrib)
+{
+ switch (attrib) {
+ case ODEV_ATTRIB_PATH:
+ case ODEV_ATTRIB_SYSPATH:
+ case ODEV_ATTRIB_BUSID:
+ return ODEV_ATTRIB_STRING;
+ case ODEV_ATTRIB_FD:
+ case ODEV_ATTRIB_MAJOR:
+ case ODEV_ATTRIB_MINOR:
+ return ODEV_ATTRIB_INT;
+ case ODEV_ATTRIB_DRIVER:
+ return ODEV_ATTRIB_STRING;
+ default:
+ LogMessage(X_ERROR, "Error %s called for unknown attribute %d\n",
+ __func__, attrib);
+ return ODEV_ATTRIB_UNKNOWN;
+ }
+}
+
Bool
config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
const char *attrib_name)
{
struct OdevAttribute *oa;
+ if (config_odev_get_attribute_type(attrib) != ODEV_ATTRIB_STRING) {
+ LogMessage(X_ERROR, "Error %s called for non string attrib %d\n",
+ __func__, attrib);
+ return FALSE;
+ }
+
oa = config_odev_find_or_add_attribute(attribs, attrib);
free(oa->attrib_name);
oa->attrib_name = XNFstrdup(attrib_name);
@@ -191,6 +217,12 @@ config_odev_add_int_attribute(struct OdevAttributes *attribs, int attrib,
{
struct OdevAttribute *oa;
+ if (config_odev_get_attribute_type(attrib) != ODEV_ATTRIB_INT) {
+ LogMessage(X_ERROR, "Error %s called for non integer attrib %d\n",
+ __func__, attrib);
+ return FALSE;
+ }
+
oa = config_odev_find_or_add_attribute(attribs, attrib);
oa->attrib_value = attrib_value;
oa->attrib_type = ODEV_ATTRIB_INT;