]> granicus.if.org Git - ipset/commitdiff
ipset: turn Set name[] into a const pointer
authorHolger Eitzenberger <holger@eitzenberger.org>
Mon, 24 Jan 2011 21:36:32 +0000 (22:36 +0100)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 25 Jan 2011 20:11:57 +0000 (21:11 +0100)
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>
include/libipset/types.h
lib/types.c

index f9c8f2d6c676abe7b58d680e29f294db2e5459a4..d8973db00905848644547a33f66c98ea9dd0a0ea 100644 (file)
@@ -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 */
index 69dac6aa3491543087668dccbf4ea05704cea869..5eb53c4f58755d0bf3fb9f01cf8f169195d8b22f 100644 (file)
@@ -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;