Blame SOURCES/0004-Fix-sbd-inquisitor-tolerate-and-strip-any-leading-sp.patch

bcce97
From 1c72cf23561deeb69b04891f3fc4d0613f73fbb0 Mon Sep 17 00:00:00 2001
bcce97
From: "Gao,Yan" <ygao@suse.com>
bcce97
Date: Fri, 25 Jun 2021 15:21:38 +0200
bcce97
Subject: [PATCH] Fix: sbd-inquisitor: tolerate and strip any leading spaces of
bcce97
 command line option values
bcce97
bcce97
Somehow an user's own monitoring agent doesn't well parse an SBD_DEVICE
bcce97
setting with spaces between the device names:
bcce97
bcce97
SBD_DEVICE="/dev/; /dev/; /dev/<c>"
bcce97
bcce97
And eventually it calls an sbd command:
bcce97
bcce97
`sbd list -d " /dev/"`
bcce97
bcce97
--  A space is prefixed to the device name which is quoted.
bcce97
bcce97
Of course it could be easily fixed in the setting or their agent. But
bcce97
OTOH, sbd'd better tolerate and strip any leading spaces of command line
bcce97
option values.
bcce97
---
bcce97
 src/sbd-inquisitor.c | 41 +++++++++++++++++++++++++----------------
bcce97
 1 file changed, 25 insertions(+), 16 deletions(-)
bcce97
bcce97
diff --git a/src/sbd-inquisitor.c b/src/sbd-inquisitor.c
bcce97
index 2cf09ac..944a353 100644
bcce97
--- a/src/sbd-inquisitor.c
bcce97
+++ b/src/sbd-inquisitor.c
bcce97
@@ -999,6 +999,15 @@ int main(int argc, char **argv, char **envp)
bcce97
         }
bcce97
 
bcce97
 	while ((c = getopt(argc, argv, "czC:DPRTWZhvw:d:n:p:1:2:3:4:5:t:I:F:S:s:r:")) != -1) {
bcce97
+		/* Call it before checking optarg for NULL to make coverity happy */
bcce97
+		const char *sanitized_optarg = sanitize_option_value(optarg);
bcce97
+
bcce97
+		if (optarg && sanitized_optarg == NULL) {
bcce97
+			fprintf(stderr, "Invalid value \"%s\" for option -%c\n", optarg, c);
bcce97
+			exit_status = -2;
bcce97
+			goto out;
bcce97
+		}
bcce97
+
bcce97
 		switch (c) {
bcce97
 		case 'D':
bcce97
 			break;
bcce97
@@ -1011,11 +1020,11 @@ int main(int argc, char **argv, char **envp)
bcce97
 			cl_log(LOG_INFO, "Realtime mode deactivated.");
bcce97
 			break;
bcce97
 		case 'S':
bcce97
-			start_mode = atoi(optarg);
bcce97
+			start_mode = atoi(sanitized_optarg);
bcce97
 			cl_log(LOG_INFO, "Start mode set to: %d", (int)start_mode);
bcce97
 			break;
bcce97
 		case 's':
bcce97
-			timeout_startup = atoi(optarg);
bcce97
+			timeout_startup = atoi(sanitized_optarg);
bcce97
 			cl_log(LOG_INFO, "Start timeout set to: %d", (int)timeout_startup);
bcce97
 			break;
bcce97
 		case 'v':
bcce97
@@ -1043,13 +1052,13 @@ int main(int argc, char **argv, char **envp)
bcce97
 			break;
bcce97
 		case 'w':
bcce97
                         free(watchdogdev);
bcce97
-                        watchdogdev = strdup(optarg);
bcce97
+                        watchdogdev = strdup(sanitized_optarg);
bcce97
                         watchdogdev_is_default = false;
bcce97
                         cl_log(LOG_NOTICE, "Using watchdog device '%s'", watchdogdev);
bcce97
 			break;
bcce97
 		case 'd':
bcce97
 #if SUPPORT_SHARED_DISK
bcce97
-			if (recruit_servant(optarg, 0) != 0) {
bcce97
+			if (recruit_servant(sanitized_optarg, 0) != 0) {
bcce97
 				fprintf(stderr, "Invalid device: %s\n", optarg);
bcce97
 				exit_status = -1;
bcce97
 				goto out;
bcce97
@@ -1070,48 +1079,48 @@ int main(int argc, char **argv, char **envp)
bcce97
 			disk_priority = 0;
bcce97
 			break;
bcce97
 		case 'n':
bcce97
-			local_uname = strdup(optarg);
bcce97
+			local_uname = strdup(sanitized_optarg);
bcce97
 			cl_log(LOG_INFO, "Overriding local hostname to %s", local_uname);
bcce97
 			break;
bcce97
 		case 'p':
bcce97
-			pidfile = strdup(optarg);
bcce97
+			pidfile = strdup(sanitized_optarg);
bcce97
 			cl_log(LOG_INFO, "pidfile set to %s", pidfile);
bcce97
 			break;
bcce97
 		case 'C':
bcce97
-			timeout_watchdog_crashdump = atoi(optarg);
bcce97
+			timeout_watchdog_crashdump = atoi(sanitized_optarg);
bcce97
 			cl_log(LOG_INFO, "Setting crashdump watchdog timeout to %d",
bcce97
 					(int)timeout_watchdog_crashdump);
bcce97
 			break;
bcce97
 		case '1':
bcce97
-			timeout_watchdog = atoi(optarg);
bcce97
+			timeout_watchdog = atoi(sanitized_optarg);
bcce97
 			break;
bcce97
 		case '2':
bcce97
-			timeout_allocate = atoi(optarg);
bcce97
+			timeout_allocate = atoi(sanitized_optarg);
bcce97
 			break;
bcce97
 		case '3':
bcce97
-			timeout_loop = atoi(optarg);
bcce97
+			timeout_loop = atoi(sanitized_optarg);
bcce97
 			break;
bcce97
 		case '4':
bcce97
-			timeout_msgwait = atoi(optarg);
bcce97
+			timeout_msgwait = atoi(sanitized_optarg);
bcce97
 			break;
bcce97
 		case '5':
bcce97
-			timeout_watchdog_warn = atoi(optarg);
bcce97
+			timeout_watchdog_warn = atoi(sanitized_optarg);
bcce97
 			do_calculate_timeout_watchdog_warn = false;
bcce97
 			cl_log(LOG_INFO, "Setting latency warning to %d",
bcce97
 					(int)timeout_watchdog_warn);
bcce97
 			break;
bcce97
 		case 't':
bcce97
-			servant_restart_interval = atoi(optarg);
bcce97
+			servant_restart_interval = atoi(sanitized_optarg);
bcce97
 			cl_log(LOG_INFO, "Setting servant restart interval to %d",
bcce97
 					(int)servant_restart_interval);
bcce97
 			break;
bcce97
 		case 'I':
bcce97
-			timeout_io = atoi(optarg);
bcce97
+			timeout_io = atoi(sanitized_optarg);
bcce97
 			cl_log(LOG_INFO, "Setting IO timeout to %d",
bcce97
 					(int)timeout_io);
bcce97
 			break;
bcce97
 		case 'F':
bcce97
-			servant_restart_count = atoi(optarg);
bcce97
+			servant_restart_count = atoi(sanitized_optarg);
bcce97
 			cl_log(LOG_INFO, "Servant restart count set to %d",
bcce97
 					(int)servant_restart_count);
bcce97
 			break;
bcce97
@@ -1119,7 +1128,7 @@ int main(int argc, char **argv, char **envp)
bcce97
 			if (timeout_action) {
bcce97
 				free(timeout_action);
bcce97
 			}
bcce97
-			timeout_action = strdup(optarg);
bcce97
+			timeout_action = strdup(sanitized_optarg);
bcce97
 			break;
bcce97
 		case 'h':
bcce97
 			usage();
bcce97
-- 
bcce97
1.8.3.1
bcce97