{"id":809408,"url":"http://patchwork.ozlabs.org/api/1.2/patches/809408/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/1504477667-12130-5-git-send-email-pablo@netfilter.org/","project":{"id":26,"url":"http://patchwork.ozlabs.org/api/1.2/projects/26/?format=json","name":"Netfilter Development","link_name":"netfilter-devel","list_id":"netfilter-devel.vger.kernel.org","list_email":"netfilter-devel@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504477667-12130-5-git-send-email-pablo@netfilter.org>","list_archive_url":null,"date":"2017-09-03T22:27:14","name":"[14/47] netlink: Introduce nla_strdup()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"4fe566a8d277e88ac011ede0cd72e8c487cb94a6","submitter":{"id":1315,"url":"http://patchwork.ozlabs.org/api/1.2/people/1315/?format=json","name":"Pablo Neira Ayuso","email":"pablo@netfilter.org"},"delegate":{"id":6139,"url":"http://patchwork.ozlabs.org/api/1.2/users/6139/?format=json","username":"pablo","first_name":"Pablo","last_name":"Neira","email":"pablo@netfilter.org"},"mbox":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/1504477667-12130-5-git-send-email-pablo@netfilter.org/mbox/","series":[{"id":1280,"url":"http://patchwork.ozlabs.org/api/1.2/series/1280/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=1280","date":"2017-09-03T22:25:42","name":"[01/47] netfilter: expect: add to hash table after expect init","version":1,"mbox":"http://patchwork.ozlabs.org/series/1280/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/809408/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/809408/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netfilter-devel-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netfilter-devel-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xlnh656tMz9s06\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  4 Sep 2017 08:28:54 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1753292AbdICW2t (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tSun, 3 Sep 2017 18:28:49 -0400","from mail.us.es ([193.147.175.20]:51168 \"EHLO mail.us.es\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1753249AbdICW2K (ORCPT <rfc822; netfilter-devel@vger.kernel.org>);\n\tSun, 3 Sep 2017 18:28:10 -0400","from antivirus1-rhel7.int (unknown [192.168.2.11])\n\tby mail.us.es (Postfix) with ESMTP id A9F8C190F65\n\tfor <netfilter-devel@vger.kernel.org>;\n\tMon,  4 Sep 2017 00:27:43 +0200 (CEST)","from antivirus1-rhel7.int (localhost [127.0.0.1])\n\tby antivirus1-rhel7.int (Postfix) with ESMTP id 9C1E2DA56C\n\tfor <netfilter-devel@vger.kernel.org>;\n\tMon,  4 Sep 2017 00:27:43 +0200 (CEST)","by antivirus1-rhel7.int (Postfix, from userid 99)\n\tid 91C4DB5030; Mon,  4 Sep 2017 00:27:43 +0200 (CEST)","from antivirus1-rhel7.int (localhost [127.0.0.1])\n\tby antivirus1-rhel7.int (Postfix) with ESMTP id 8A71AB5024;\n\tMon,  4 Sep 2017 00:27:41 +0200 (CEST)","from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int\n\t(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); \n\tMon, 04 Sep 2017 00:27:41 +0200 (CEST)","from salvia.here (unknown [31.4.193.113])\n\t(Authenticated sender: pneira@us.es)\n\tby entrada.int (Postfix) with ESMTPA id 453F04265A20;\n\tMon,  4 Sep 2017 00:27:41 +0200 (CEST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.1 (2015-04-28) on\n\tantivirus1-rhel7.int","X-Spam-Level":"","X-Spam-Status":"No, score=-108.2 required=7.5 tests=ALL_TRUSTED,BAYES_50,\n\tSMTPAUTH_US2,USER_IN_WHITELIST autolearn=disabled version=3.4.1","X-Virus-Status":"clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int)","X-SMTPAUTHUS":"auth mail.us.es","From":"Pablo Neira Ayuso <pablo@netfilter.org>","To":"netfilter-devel@vger.kernel.org","Cc":"davem@davemloft.net, netdev@vger.kernel.org","Subject":"[PATCH 14/47] netlink: Introduce nla_strdup()","Date":"Mon,  4 Sep 2017 00:27:14 +0200","Message-Id":"<1504477667-12130-5-git-send-email-pablo@netfilter.org>","X-Mailer":"git-send-email 2.1.4","In-Reply-To":"<1504477667-12130-1-git-send-email-pablo@netfilter.org>","References":"<1504477667-12130-1-git-send-email-pablo@netfilter.org>","X-Virus-Scanned":"ClamAV using ClamSMTP","Sender":"netfilter-devel-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netfilter-devel.vger.kernel.org>","X-Mailing-List":"netfilter-devel@vger.kernel.org"},"content":"From: Phil Sutter <phil@nwl.cc>\n\nThis is similar to strdup() for netlink string attributes.\n\nSigned-off-by: Phil Sutter <phil@nwl.cc>\nSigned-off-by: Pablo Neira Ayuso <pablo@netfilter.org>\n---\n include/net/netlink.h |  1 +\n lib/nlattr.c          | 24 ++++++++++++++++++++++++\n 2 files changed, 25 insertions(+)","diff":"diff --git a/include/net/netlink.h b/include/net/netlink.h\nindex ef8e6c3a80a6..c8c2eb5ae55e 100644\n--- a/include/net/netlink.h\n+++ b/include/net/netlink.h\n@@ -247,6 +247,7 @@ int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head,\n int nla_policy_len(const struct nla_policy *, int);\n struct nlattr *nla_find(const struct nlattr *head, int len, int attrtype);\n size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize);\n+char *nla_strdup(const struct nlattr *nla, gfp_t flags);\n int nla_memcpy(void *dest, const struct nlattr *src, int count);\n int nla_memcmp(const struct nlattr *nla, const void *data, size_t size);\n int nla_strcmp(const struct nlattr *nla, const char *str);\ndiff --git a/lib/nlattr.c b/lib/nlattr.c\nindex fb52435be42d..f13013f7e21a 100644\n--- a/lib/nlattr.c\n+++ b/lib/nlattr.c\n@@ -272,6 +272,30 @@ size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)\n EXPORT_SYMBOL(nla_strlcpy);\n \n /**\n+ * nla_strdup - Copy string attribute payload into a newly allocated buffer\n+ * @nla: attribute to copy the string from\n+ * @flags: the type of memory to allocate (see kmalloc).\n+ *\n+ * Returns a pointer to the allocated buffer or NULL on error.\n+ */\n+char *nla_strdup(const struct nlattr *nla, gfp_t flags)\n+{\n+\tsize_t srclen = nla_len(nla);\n+\tchar *src = nla_data(nla), *dst;\n+\n+\tif (srclen > 0 && src[srclen - 1] == '\\0')\n+\t\tsrclen--;\n+\n+\tdst = kmalloc(srclen + 1, flags);\n+\tif (dst != NULL) {\n+\t\tmemcpy(dst, src, srclen);\n+\t\tdst[srclen] = '\\0';\n+\t}\n+\treturn dst;\n+}\n+EXPORT_SYMBOL(nla_strdup);\n+\n+/**\n  * nla_memcpy - Copy a netlink attribute into another memory area\n  * @dest: where to copy to memcpy\n  * @src: netlink attribute to copy from\n","prefixes":["14/47"]}