summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Egerer <thomas.egerer@secunet.com>2016-06-10 09:57:53 (GMT)
committerThomas Haller <thaller@redhat.com>2016-06-25 15:21:58 (GMT)
commitfa1076eaac91b9a68be9465a1a92d47f8c7fe23e (patch)
tree43b4383d0c155ad89c9bb3b9880b99a8fdc198ea
parent6a9b59ca731c739fd4a5e3cbcac28309ec427f4b (diff)
downloadlibnl-fa1076eaac91b9a68be9465a1a92d47f8c7fe23e.zip
libnl-fa1076eaac91b9a68be9465a1a92d47f8c7fe23e.tar.gz
libnl-fa1076eaac91b9a68be9465a1a92d47f8c7fe23e.tar.bz2
xfrm: fix segfault when using encapsulation templates
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com> Signed-off-by: Thomas Haller <thaller@redhat.com> http://lists.infradead.org/pipermail/libnl/2016-June/002140.html
-rw-r--r--lib/xfrm/sa.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c
index 0b813c4..7e663bb 100644
--- a/lib/xfrm/sa.c
+++ b/lib/xfrm/sa.c
@@ -1773,9 +1773,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;