From: lixiaokeng Subject: [PATCH V3 09/14] libmultipath: check whether mp->features is NUll in assemble_map Date: Tue, 8 Sep 2020 16:51:07 +0800 Message-ID: <13d81368-18be-3961-df65-34fed5bf1bce@huawei.com> References: <2fb59aa1-eafa-49b6-08aa-a279565ec234@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <2fb59aa1-eafa-49b6-08aa-a279565ec234@huawei.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Content-Language: en-GB To: Christophe Varoqui , Martin Wilck , Benjamin Marzinski , dm-devel mailing list Cc: linfeilong , "liuzhiqiang (I)" List-Id: dm-devel.ids In assemble_map func, if add_feature fails and mp->features is default value (NULL), STRDUP(mp->features) will cause a seg-fault. In addition, f = STRDUP(mp->features) is just used for APPEND(). We can directly pass mp->features to APPEND(). Here, we firstly check whether mp->features is null. V1->V2: use ?: instead of checking mp->features Signed-off-by: Zhiqiang Liu Signed-off-by: lixiaokeng --- libmultipath/dmparser.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c index 482e9d0e..3c5e016a 100644 --- a/libmultipath/dmparser.c +++ b/libmultipath/dmparser.c @@ -65,7 +65,7 @@ assemble_map (struct multipath * mp, char * params, int len) int i, j; int minio; int nr_priority_groups, initial_pg_nr; - char * p, * f; + char * p; const char *const end = params + len; char no_path_retry[] = "queue_if_no_path"; char retain_hwhandler[] = "retain_attached_hw_handler"; @@ -86,10 +86,8 @@ assemble_map (struct multipath * mp, char * params, int len) get_linux_version_code() < KERNEL_VERSION(4, 3, 0)) add_feature(&mp->features, retain_hwhandler); - f = STRDUP(mp->features); - - APPEND(p, end, "%s %s %i %i", f, mp->hwhandler, nr_priority_groups, - initial_pg_nr); + APPEND(p, end, "%s %s %i %i", mp->features ? mp->features : 0, mp->hwhandler, + nr_priority_groups, initial_pg_nr); vector_foreach_slot (mp->pg, pgp, i) { pgp = VECTOR_SLOT(mp->pg, i); @@ -110,12 +108,10 @@ assemble_map (struct multipath * mp, char * params, int len) } } - FREE(f); condlog(4, "%s: assembled map [%s]", mp->alias, params); return 0; err: - FREE(f); return 1; } --