summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Eitzenberger <holger@eitzenberger.org>2011-01-24 22:36:32 +0100
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2011-01-25 21:11:57 +0100
commitba623ef3b9ce8f2a92f0f1e47163468932816ab3 (patch)
tree627db653f2265d514fd2d504c25ede1cca358695
parentd3b9fa094d693f05a747eda21db715a5bbf8dbbc (diff)
ipset: turn Set name[] into a const pointer
Also check for the name length. Note that passing errno values back is not done consistently at various place, as there are some functions which set errno manually, others pass -errno back. I use the -errno approach here, as it is slightly shorter. Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org> Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-rw-r--r--include/libipset/types.h2
-rw-r--r--lib/types.c17
2 files changed, 10 insertions, 9 deletions
diff --git a/include/libipset/types.h b/include/libipset/types.h
index f9c8f2d..d8973db 100644
--- a/include/libipset/types.h
+++ b/include/libipset/types.h
@@ -70,7 +70,7 @@ struct ipset_elem {
* but for the readability the full list is supported.
*/
struct ipset_type {
- char name[IPSET_MAXNAMELEN]; /* type name */
+ const char *name;
uint8_t revision; /* revision number */
uint8_t family; /* supported family */
uint8_t dimension; /* elem dimension */
diff --git a/lib/types.c b/lib/types.c
index 69dac6a..5eb53c4 100644
--- a/lib/types.c
+++ b/lib/types.c
@@ -441,13 +441,15 @@ ipset_type_add(struct ipset_type *type)
assert(type);
+ if (strlen(type->name) > IPSET_MAXNAMELEN - 1)
+ return -EINVAL;
+
/* Add to the list: higher revision numbers first */
for (t = typelist, prev = NULL; t != NULL; t = t->next) {
if (STREQ(t->name, type->name)) {
- if (t->revision == type->revision) {
- errno = EEXIST;
- return -1;
- } else if (t->revision < type->revision) {
+ if (t->revision == type->revision)
+ return -EEXIST;
+ else if (t->revision < type->revision) {
type->next = t;
if (prev)
prev->next = type;
@@ -457,10 +459,9 @@ ipset_type_add(struct ipset_type *type)
}
}
if (t->next != NULL && STREQ(t->next->name, type->name)) {
- if (t->next->revision == type->revision) {
- errno = EEXIST;
- return -1;
- } else if (t->next->revision < type->revision) {
+ if (t->next->revision == type->revision)
+ return -EEXIST;
+ else if (t->next->revision < type->revision) {
type->next = t->next;
t->next = type;
return 0;