From ba623ef3b9ce8f2a92f0f1e47163468932816ab3 Mon Sep 17 00:00:00 2001 From: Holger Eitzenberger Date: Mon, 24 Jan 2011 22:36:32 +0100 Subject: 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 Signed-off-by: Jozsef Kadlecsik --- lib/types.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/types.c') 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; -- cgit v1.2.3