[PATCH 1/3] xfrm: Fix segfault when using encapsulation templates

Thomas Egerer thomas.egerer at secunet.com
Fri Jun 10 02:57:53 PDT 2016


Signed-off-by: Thomas Egerer <thomas.egerer at secunet.com>
---
 lib/xfrm/sa.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c
index b17988c..b330409 100644
--- a/lib/xfrm/sa.c
+++ b/lib/xfrm/sa.c
@@ -1772,9 +1772,14 @@ int xfrmnl_sa_get_encap_tmpl (struct xfrmnl_sa* sa, unsigned int* encap_type, un
 
 int xfrmnl_sa_set_encap_tmpl (struct xfrmnl_sa* sa, unsigned int encap_type, unsigned int encap_sport, unsigned int encap_dport, struct nl_addr* encap_oa)
 {
-	/* Free up the old encap OA */
-	if (sa->encap->encap_oa)
-		nl_addr_put (sa->encap->encap_oa);
+	if (sa->encap) {
+		/* Free up the old encap OA */
+		if (sa->encap->encap_oa)
+			nl_addr_put(sa->encap->encap_oa);
+		free(sa->encap);
+	}
+	if ((sa->encap = calloc(1, sizeof(*sa->encap))) == NULL)
+		return -1;
 
 	/* Save the new info */
 	sa->encap->encap_type   =   encap_type;
-- 
2.1.3





More information about the libnl mailing list