netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2 libnftnl] set_elem: Copy user data memory
@ 2016-05-27 14:56 Carlos Falgueras García
  2016-05-27 14:56 ` [PATCH 2/2 nft] set_elem: Use libnftnl/udata to store set element comment Carlos Falgueras García
  2016-05-30  9:46 ` [PATCH 1/2 libnftnl] set_elem: Copy user data memory Pablo Neira Ayuso
  0 siblings, 2 replies; 4+ messages in thread
From: Carlos Falgueras García @ 2016-05-27 14:56 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo

All attributes are passed by copy, so user data should be copied too.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
---
 src/set_elem.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/set_elem.c b/src/set_elem.c
index 990be24..b9c7e1e 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -125,8 +125,14 @@ void nftnl_set_elem_set(struct nftnl_set_elem *s, uint16_t attr,
 		s->timeout = *((uint64_t *)data);
 		break;
 	case NFTNL_SET_ELEM_USERDATA: /* NFTA_SET_ELEM_USERDATA */
-		s->user.data = (void *)data;
-		s->user.len  = data_len;
+		if (s->user.data != NULL)
+			xfree(s->user.data);
+
+		s->user.data = malloc(data_len);
+		if (!s->user.data)
+			return;
+		memcpy(s->user.data, data, data_len);
+		s->user.len = data_len;
 		break;
 	default:
 		return;
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-05-30  9:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-27 14:56 [PATCH 1/2 libnftnl] set_elem: Copy user data memory Carlos Falgueras García
2016-05-27 14:56 ` [PATCH 2/2 nft] set_elem: Use libnftnl/udata to store set element comment Carlos Falgueras García
2016-05-30  9:47   ` Pablo Neira Ayuso
2016-05-30  9:46 ` [PATCH 1/2 libnftnl] set_elem: Copy user data memory Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).