Blame SOURCES/bz1508435-no-segfault-ip_vs-load.patch

9cfb40
From 19d0482859d9068b893104b9f8beeaba709aec2d Mon Sep 17 00:00:00 2001
9cfb40
From: Quentin Armitage <quentin@armitage.org.uk>
9cfb40
Date: Mon, 27 Mar 2017 11:28:02 +0100
9cfb40
Subject: [PATCH 2/3] Don't segfault if unable to load ip_vs module
9cfb40
9cfb40
In a docker container it isn't possible to load a kernel module. The
9cfb40
check code was detecting that it couldn't load the module, but the
9cfb40
checker process, when cleaning up prior to exiting, was assuming that
9cfb40
certain pointers had been initialised which hadn't been when an error
9cfb40
was detected so early in the initialisation.
9cfb40
9cfb40
This commit adds testing for uninitialised pointers during the exit
9cfb40
sequence.
9cfb40
9cfb40
Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
9cfb40
---
9cfb40
 keepalived/check/check_api.c         | 3 +++
9cfb40
 keepalived/check/check_daemon.c      | 8 +++++---
9cfb40
 keepalived/check/check_data.c        | 7 ++++++-
9cfb40
 keepalived/check/ipvswrapper.c       | 9 ++++++---
9cfb40
 keepalived/check/ipwrapper.c         | 6 ++++--
9cfb40
 keepalived/check/libipvs.c           | 5 ++++-
9cfb40
 keepalived/core/keepalived_netlink.c | 7 ++++---
9cfb40
 7 files changed, 32 insertions(+), 13 deletions(-)
9cfb40
9cfb40
diff --git a/keepalived/check/check_api.c b/keepalived/check/check_api.c
9cfb40
index 51d8cc71..b7081fd0 100644
9cfb40
--- a/keepalived/check/check_api.c
9cfb40
+++ b/keepalived/check/check_api.c
9cfb40
@@ -224,6 +224,9 @@ init_checkers_queue(void)
9cfb40
 void
9cfb40
 free_checkers_queue(void)
9cfb40
 {
9cfb40
+	if (!checkers_queue)
9cfb40
+		return;
9cfb40
+
9cfb40
 	free_list(&checkers_queue);
9cfb40
 	ncheckers = 0;
9cfb40
 }
9cfb40
diff --git a/keepalived/check/check_daemon.c b/keepalived/check/check_daemon.c
9cfb40
index a87fd4cd..a3ff8cab 100644
9cfb40
--- a/keepalived/check/check_daemon.c
9cfb40
+++ b/keepalived/check/check_daemon.c
9cfb40
@@ -74,7 +74,7 @@ stop_check(int status)
9cfb40
 		clear_services();
9cfb40
 	ipvs_stop();
9cfb40
 #ifdef _WITH_SNMP_CHECKER_
9cfb40
-	if (global_data->enable_snmp_checker)
9cfb40
+	if (global_data && global_data->enable_snmp_checker)
9cfb40
 		check_snmp_agent_close();
9cfb40
 #endif
9cfb40
 
9cfb40
@@ -82,8 +82,10 @@ stop_check(int status)
9cfb40
 	pidfile_rm(checkers_pidfile);
9cfb40
 
9cfb40
 	/* Clean data */
9cfb40
-	free_global_data(global_data);
9cfb40
-	free_check_data(check_data);
9cfb40
+	if (global_data)
9cfb40
+		free_global_data(global_data);
9cfb40
+	if (check_data)
9cfb40
+		free_check_data(check_data);
9cfb40
 	free_parent_mallocs_exit();
9cfb40
 
9cfb40
 	/*
9cfb40
diff --git a/keepalived/check/check_data.c b/keepalived/check/check_data.c
9cfb40
index 0c3f1940..6ce87229 100644
9cfb40
--- a/keepalived/check/check_data.c
9cfb40
+++ b/keepalived/check/check_data.c
9cfb40
@@ -51,7 +51,12 @@ alloc_ssl(void)
9cfb40
 void
9cfb40
 free_ssl(void)
9cfb40
 {
9cfb40
-	ssl_data_t *ssl = check_data->ssl;
9cfb40
+	ssl_data_t *ssl;
9cfb40
+       
9cfb40
+	if (!check_data)
9cfb40
+		return;
9cfb40
+
9cfb40
+	ssl = check_data->ssl;
9cfb40
 
9cfb40
 	if (!ssl)
9cfb40
 		return;
9cfb40
diff --git a/keepalived/check/ipvswrapper.c b/keepalived/check/ipvswrapper.c
9cfb40
index cd7f169e..20757c94 100644
9cfb40
--- a/keepalived/check/ipvswrapper.c
9cfb40
+++ b/keepalived/check/ipvswrapper.c
9cfb40
@@ -165,9 +165,12 @@ void
9cfb40
 ipvs_stop(void)
9cfb40
 {
9cfb40
 	/* Clean up the room */
9cfb40
-	FREE(srule);
9cfb40
-	FREE(drule);
9cfb40
-	FREE(daemonrule);
9cfb40
+	if (srule)
9cfb40
+		FREE(srule);
9cfb40
+	if (drule)
9cfb40
+		FREE(drule);
9cfb40
+	if (daemonrule)
9cfb40
+		FREE(daemonrule);
9cfb40
 	ipvs_close();
9cfb40
 }
9cfb40
 
9cfb40
diff --git a/keepalived/check/ipwrapper.c b/keepalived/check/ipwrapper.c
9cfb40
index 0c2fc46b..ecf12713 100644
9cfb40
--- a/keepalived/check/ipwrapper.c
9cfb40
+++ b/keepalived/check/ipwrapper.c
9cfb40
@@ -138,10 +138,12 @@ void
9cfb40
 clear_services(void)
9cfb40
 {
9cfb40
 	element e;
9cfb40
-	list l = check_data->vs;
9cfb40
 	virtual_server_t *vs;
9cfb40
 
9cfb40
-	for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) {
9cfb40
+	if (!check_data || !check_data->vs)
9cfb40
+		return;
9cfb40
+
9cfb40
+	for (e = LIST_HEAD(check_data->vs); e; ELEMENT_NEXT(e)) {
9cfb40
 		vs = ELEMENT_DATA(e);
9cfb40
 		clear_service_vs(vs);
9cfb40
 	}
9cfb40
diff --git a/keepalived/check/libipvs.c b/keepalived/check/libipvs.c
9cfb40
index 2250e2b4..8722f7a6 100644
9cfb40
--- a/keepalived/check/libipvs.c
9cfb40
+++ b/keepalived/check/libipvs.c
9cfb40
@@ -1157,7 +1157,10 @@ void ipvs_close(void)
9cfb40
 	if (try_nl)
9cfb40
 		return;
9cfb40
 #endif
9cfb40
-	close(sockfd);
9cfb40
+	if (sockfd != -1) {
9cfb40
+		close(sockfd);
9cfb40
+		sockfd = -1;
9cfb40
+	}
9cfb40
 }
9cfb40
 
9cfb40
 const char *ipvs_strerror(int err)
9cfb40
diff --git a/keepalived/core/keepalived_netlink.c b/keepalived/core/keepalived_netlink.c
9cfb40
index 41e63b85..0f465cf5 100644
9cfb40
--- a/keepalived/core/keepalived_netlink.c
9cfb40
+++ b/keepalived/core/keepalived_netlink.c
9cfb40
@@ -251,9 +251,12 @@ netlink_socket(nl_handle_t *nl, int flags, int group, ...)
9cfb40
 }
9cfb40
 
9cfb40
 /* Close a netlink socket */
9cfb40
-static int
9cfb40
+static void
9cfb40
 netlink_close(nl_handle_t *nl)
9cfb40
 {
9cfb40
+	if (!nl)
9cfb40
+		return;
9cfb40
+
9cfb40
 	/* First of all release pending thread */
9cfb40
 	thread_cancel(nl->thread);
9cfb40
 
9cfb40
@@ -269,8 +272,6 @@ netlink_close(nl_handle_t *nl)
9cfb40
 #endif
9cfb40
 		close(nl->fd);
9cfb40
 #endif
9cfb40
-
9cfb40
-	return 0;
9cfb40
 }
9cfb40
 
9cfb40
 #ifdef _WITH_VRRP_
9cfb40
-- 
9cfb40
2.13.5
9cfb40