Blame SOURCES/0002-examples-fix-double-free-in-nftc-helper-add.patch

443ef4
From 7b175a4fc9f81fe3f721d9a7ebb5b954a4fd7606 Mon Sep 17 00:00:00 2001
443ef4
From: Liping Zhang <zlpnobody@gmail.com>
443ef4
Date: Sun, 19 Mar 2017 22:01:10 +0800
443ef4
Subject: [PATCH] examples: fix double free in nftc-helper-add
443ef4
443ef4
After inputting the following test command, core dump happened:
443ef4
  # ./examples/nfct-helper-add test 1
443ef4
  *** Error in
443ef4
 `.../libnetfilter_cthelper/examples/.libs/lt-nfct-helper-add':
443ef4
  double free or corruption (fasttop): 0x0000000001f3c070 ***
443ef4
  ======= Backtrace: =========
443ef4
  /lib64/libc.so.6(+0x77de5)[0x7fd9ebe88de5]
443ef4
  /lib64/libc.so.6(+0x8022a)[0x7fd9ebe9122a]
443ef4
  /lib64/libc.so.6(cfree+0x4c)[0x7fd9ebe9478c]
443ef4
  [...]
443ef4
443ef4
Because "struct nfct_helper_policy *p" had been freed by nfct_helper_free,
443ef4
so there's no need to invoke nfct_helper_policy_free again, otherwise
443ef4
double free error will happen.
443ef4
443ef4
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
443ef4
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
443ef4
(cherry picked from commit 9f223e612d3b0be6e4dca84e1db8042dbec64e93)
443ef4
---
443ef4
 examples/nfct-helper-add.c | 2 +-
443ef4
 1 file changed, 1 insertion(+), 1 deletion(-)
443ef4
443ef4
diff --git a/examples/nfct-helper-add.c b/examples/nfct-helper-add.c
443ef4
index 6c476261b75e8..cb7291e8ec4b0 100644
443ef4
--- a/examples/nfct-helper-add.c
443ef4
+++ b/examples/nfct-helper-add.c
443ef4
@@ -32,6 +32,7 @@ int main(int argc, char *argv[])
443ef4
 	nfct_helper_attr_set_u16(nfct_helper, NFCTH_ATTR_PROTO_L3NUM, AF_INET);
443ef4
 	nfct_helper_attr_set_u8(nfct_helper, NFCTH_ATTR_PROTO_L4NUM, IPPROTO_TCP);
443ef4
 
443ef4
+	/* Will be freed by nfct_helper_free. */
443ef4
 	p = nfct_helper_policy_alloc();
443ef4
 	if (p == NULL) {
443ef4
 		perror("OOM");
443ef4
@@ -49,7 +50,6 @@ int main(int argc, char *argv[])
443ef4
 	nfct_helper_nlmsg_build_payload(nlh, nfct_helper);
443ef4
 
443ef4
 	nfct_helper_free(nfct_helper);
443ef4
-	nfct_helper_policy_free(p);
443ef4
 
443ef4
 	nl = mnl_socket_open(NETLINK_NETFILTER);
443ef4
 	if (nl == NULL) {
443ef4
-- 
443ef4
2.21.0
443ef4