return *dirp;
}
-/* Maximum length of the BRC_GENL_A_PROC_DIR and BRC_GENL_A_PROC_NAME strings.
- * If we could depend on supporting NLA_NUL_STRING and the .len member in
- * Generic Netlink policy, then we could just put this in brc_genl_policy (and
- * simplify brc_genl_set_proc() below too), but upstream 2.6.18 does not have
- * either. */
-#define BRC_NAME_LEN_MAX 32
-
int brc_genl_set_proc(struct sk_buff *skb, struct genl_info *info)
{
struct proc_dir_entry *dir, *entry;
char *data;
if (!info->attrs[BRC_GENL_A_PROC_DIR] ||
- VERIFY_NUL_STRING(info->attrs[BRC_GENL_A_PROC_DIR]) ||
+ VERIFY_NUL_STRING(info->attrs[BRC_GENL_A_PROC_DIR], BRC_NAME_LEN_MAX) ||
!info->attrs[BRC_GENL_A_PROC_NAME] ||
- VERIFY_NUL_STRING(info->attrs[BRC_GENL_A_PROC_NAME]) ||
+ VERIFY_NUL_STRING(info->attrs[BRC_GENL_A_PROC_NAME], BRC_NAME_LEN_MAX) ||
(info->attrs[BRC_GENL_A_PROC_DATA] &&
- VERIFY_NUL_STRING(info->attrs[BRC_GENL_A_PROC_DATA])))
+ VERIFY_NUL_STRING(info->attrs[BRC_GENL_A_PROC_DATA], INT_MAX)))
return -EINVAL;
dir_name = nla_data(info->attrs[BRC_GENL_A_PROC_DIR]);
name = nla_data(info->attrs[BRC_GENL_A_PROC_NAME]);
- if (strlen(dir_name) > BRC_NAME_LEN_MAX ||
- strlen(name) > BRC_NAME_LEN_MAX)
- return -EINVAL;
if (!strcmp(dir_name, "net/vlan"))
dir = brc_open_dir("vlan", proc_net, &proc_vlan_dir);
/*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009, 2011 Nicira Networks.
* Distributed under the terms of the GNU GPL version 2.
*
* Significant portions of this file may be copied from parts of the Linux
struct sk_buff;
struct genl_info;
+/* Maximum length of BRC_GENL_A_PROC_DIR and BRC_GENL_A_PROC_NAME strings. */
+#define BRC_NAME_LEN_MAX 32
+
void brc_procfs_exit(void);
int brc_genl_set_proc(struct sk_buff *skb, struct genl_info *info);
static struct nla_policy brc_genl_policy[BRC_GENL_A_MAX + 1] = {
[BRC_GENL_A_ERR_CODE] = { .type = NLA_U32 },
- [BRC_GENL_A_PROC_DIR] = { .type = NLA_NUL_STRING },
- [BRC_GENL_A_PROC_NAME] = { .type = NLA_NUL_STRING },
+#ifdef HAVE_NLA_NUL_STRING
+ [BRC_GENL_A_PROC_DIR] = { .type = NLA_NUL_STRING,
+ .len = BRC_NAME_LEN_MAX },
+ [BRC_GENL_A_PROC_NAME] = { .type = NLA_NUL_STRING,
+ .len = BRC_NAME_LEN_MAX },
[BRC_GENL_A_PROC_DATA] = { .type = NLA_NUL_STRING },
+#endif
[BRC_GENL_A_FDB_DATA] = { .type = NLA_UNSPEC },
};
#include_next <net/netlink.h>
#ifndef HAVE_NLA_NUL_STRING
-#define NLA_NUL_STRING NLA_STRING
-
-static inline int VERIFY_NUL_STRING(struct nlattr *attr)
+static inline int VERIFY_NUL_STRING(struct nlattr *attr, int maxlen)
{
- return (!attr || (nla_len(attr)
- && memchr(nla_data(attr), '\0', nla_len(attr)))
- ? 0 : -EINVAL);
+ char *s;
+ int len;
+ if (!attr)
+ return 0;
+
+ len = nla_len(attr);
+ if (len >= maxlen)
+ return -EINVAL;
+
+ s = nla_data(attr);
+ if (s[len - 1] != '\0')
+ return -EINVAL;
+
+ return 0;
}
#else
-static inline int VERIFY_NUL_STRING(struct nlattr *attr)
+static inline int VERIFY_NUL_STRING(struct nlattr *attr, int maxlen)
{
return 0;
}