#include <fcntl.h>
#include <signal.h>
#include <sys/poll.h>
+#include <stdbool.h>
#include "control_local.h"
/**
return ctl->ops->element_info(ctl, info);
}
+static bool validate_element_member_dimension(snd_ctl_elem_info_t *info)
+{
+ unsigned int members;
+ unsigned int i;
+
+ if (info->dimen.d[0] == 0)
+ return true;
+
+ members = 1;
+ for (i = 0; i < ARRAY_SIZE(info->dimen.d); ++i) {
+ if (info->dimen.d[i] == 0)
+ break;
+ members *= info->dimen.d[i];
+
+ if (members > info->count)
+ return false;
+ }
+
+ for (++i; i < ARRAY_SIZE(info->dimen.d); ++i) {
+ if (info->dimen.d[i] > 0)
+ return false;
+ }
+
+ return members == info->count;
+}
+
/**
* \brief Create and add some user-defined control elements of integer type.
* \param ctl A handle of backend module for control interface.
info->value.integer.max = max;
info->value.integer.step = step;
+ if (!validate_element_member_dimension(info))
+ return -EINVAL;
+
err = ctl->ops->element_add(ctl, info);
if (err < 0)
return err;
info->value.integer64.max = max;
info->value.integer64.step = step;
+ if (!validate_element_member_dimension(info))
+ return -EINVAL;
+
err = ctl->ops->element_add(ctl, info);
if (err < 0)
return err;
info->value.integer.min = 0;
info->value.integer.max = 1;
+ if (!validate_element_member_dimension(info))
+ return -EINVAL;
+
return ctl->ops->element_add(ctl, info);
}
p += strlen(labels[i]) + 1;
}
+ if (!validate_element_member_dimension(info))
+ return -EINVAL;
+
err = ctl->ops->element_add(ctl, info);
free(buf);
info->owner = element_count;
info->count = member_count;
+ if (!validate_element_member_dimension(info))
+ return -EINVAL;
+
return ctl->ops->element_add(ctl, info);
}