From 27594c740e16f6c530a4497a789427033e27bb81 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Tue, 3 Aug 2021 15:29:16 -0500 Subject: [PATCH] device-mapper-multipath-0.8.6-6 Add 0022-multipathd-cli_handlers-cleanup-setting-reply-length.patch * Found by corosync Related: bz #1984921 --- ...andlers-cleanup-setting-reply-length.patch | 82 +++++++++++++++++++ device-mapper-multipath.spec | 8 +- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 0022-multipathd-cli_handlers-cleanup-setting-reply-length.patch diff --git a/0022-multipathd-cli_handlers-cleanup-setting-reply-length.patch b/0022-multipathd-cli_handlers-cleanup-setting-reply-length.patch new file mode 100644 index 0000000..3099df6 --- /dev/null +++ b/0022-multipathd-cli_handlers-cleanup-setting-reply-length.patch @@ -0,0 +1,82 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Martin Wilck +Date: Mon, 17 May 2021 22:37:34 +0200 +Subject: [PATCH] multipathd: cli_handlers: cleanup setting reply length + +Create a macro for setting the reply length for string literals +correctly, and use it where necessary. + +In cli_del_path(), don't change the function's return code +if just the buffer allocation for the reply failed. + +Reviewed-by: Benjamin Marzinski +Signed-off-by: Benjamin Marzinski +--- + multipathd/cli_handlers.c | 33 ++++++++++++--------------------- + 1 file changed, 12 insertions(+), 21 deletions(-) + +diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c +index 6765fcf0..96064944 100644 +--- a/multipathd/cli_handlers.c ++++ b/multipathd/cli_handlers.c +@@ -32,6 +32,12 @@ + #include "foreign.h" + #include "cli_handlers.h" + ++#define SET_REPLY_AND_LEN(__rep, __len, string_literal) \ ++ do { \ ++ *(__rep) = strdup(string_literal); \ ++ *(__len) = *(__rep) ? sizeof(string_literal) : 0; \ ++ } while (0) ++ + int + show_paths (char ** r, int * len, struct vectors * vecs, char * style, + int pretty) +@@ -802,8 +808,7 @@ cli_add_path (void * v, char ** reply, int * len, void * data) + } + return ev_add_path(pp, vecs, 1); + blacklisted: +- *reply = strdup("blacklisted\n"); +- *len = strlen(*reply) + 1; ++ SET_REPLY_AND_LEN(reply, len, "blacklisted\n"); + condlog(2, "%s: path blacklisted", param); + return 0; + } +@@ -824,23 +829,10 @@ cli_del_path (void * v, char ** reply, int * len, void * data) + return 1; + } + ret = ev_remove_path(pp, vecs, 1); +- if (ret == REMOVE_PATH_DELAY) { +- *reply = strdup("delayed\n"); +- if (*reply) +- *len = strlen(*reply) + 1; +- else { +- *len = 0; +- ret = REMOVE_PATH_FAILURE; +- } +- } else if (ret == REMOVE_PATH_MAP_ERROR) { +- *reply = strdup("map reload error. removed\n"); +- if (*reply) +- *len = strlen(*reply) + 1; +- else { +- *len = 0; +- ret = REMOVE_PATH_FAILURE; +- } +- } ++ if (ret == REMOVE_PATH_DELAY) ++ SET_REPLY_AND_LEN(reply, len, "delayed\n"); ++ else if (ret == REMOVE_PATH_MAP_ERROR) ++ SET_REPLY_AND_LEN(reply, len, "map reload error. removed\n"); + return (ret == REMOVE_PATH_FAILURE); + } + +@@ -865,8 +857,7 @@ cli_add_map (void * v, char ** reply, int * len, void * data) + invalid = 1; + pthread_cleanup_pop(1); + if (invalid) { +- *reply = strdup("blacklisted\n"); +- *len = strlen(*reply) + 1; ++ SET_REPLY_AND_LEN(reply, len, "blacklisted\n"); + condlog(2, "%s: map blacklisted", param); + return 1; + } diff --git a/device-mapper-multipath.spec b/device-mapper-multipath.spec index 1f0bdc5..4ab8977 100644 --- a/device-mapper-multipath.spec +++ b/device-mapper-multipath.spec @@ -1,6 +1,6 @@ Name: device-mapper-multipath Version: 0.8.6 -Release: 5%{?dist} +Release: 6%{?dist} Summary: Tools to manage multipath devices using device-mapper License: GPLv2 URL: http://christophe.varoqui.free.fr/ @@ -31,6 +31,7 @@ Patch0018: 0018-multipath.conf-fix-typo-in-ghost_delay-description.patch Patch0019: 0019-mpathpersist-fail-commands-when-no-usable-paths-exis.patch Patch0020: 0020-multipath-print-warning-if-multipathd-is-not-running.patch Patch0021: 0021-libmultipath-deal-with-dynamic-PTHREAD_STACK_MIN.patch +Patch0022: 0022-multipathd-cli_handlers-cleanup-setting-reply-length.patch # runtime Requires: %{name}-libs = %{version}-%{release} @@ -229,6 +230,11 @@ fi %{_pkgconfdir}/libdmmp.pc %changelog +* Fri Jul 23 2021 Benjamin Marzinski - 0.8.6-6 +- Add 0022-multipathd-cli_handlers-cleanup-setting-reply-length.patch + * Found by corosync +- Related: bz #1984921 + * Fri Jul 23 2021 Benjamin Marzinski - 0.8.6-5 - Add 0018-multipath.conf-fix-typo-in-ghost_delay-description.patch - Add 0019-mpathpersist-fail-commands-when-no-usable-paths-exis.patch