]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
attr: Warn application if nla_parse() observes same attribute multiple times
authorThomas Graf <tgraf@suug.ch>
Wed, 13 Mar 2013 16:12:03 +0000 (17:12 +0100)
committerThomas Graf <tgraf@suug.ch>
Thu, 14 Mar 2013 11:46:09 +0000 (12:46 +0100)
Use a debugging message to warn applications if an attribute is
found multiple times in the same message. It is perfectly valid
to rely on this behaviour but it is likely to indicate a bug.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
lib/attr.c

index 093ffb5de570477291cb0af89537d7d92cdef866..e6efe4ee5ffa62f0f7d24508acf9bf1283f5ef86 100644 (file)
@@ -254,15 +254,20 @@ int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len,
                if (type == 0)
                        continue;
 
-               if (type <= maxtype) {
-                       if (policy) {
-                               err = validate_nla(nla, maxtype, policy);
-                               if (err < 0)
-                                       goto errout;
-                       }
-
-                       tb[type] = nla;
+               if (type > maxtype)
+                       continue;
+
+               if (policy) {
+                       err = validate_nla(nla, maxtype, policy);
+                       if (err < 0)
+                               goto errout;
                }
+
+               if (tb[type])
+                       NL_DBG(1, "Attribute of type %#x found multiple times in message, "
+                                 "previous attribute is being ignored.\n", type);
+
+               tb[type] = nla;
        }
 
        if (rem > 0)