From: lixiaokeng Subject: [PATCH 08/14] libmultipath: donot free *dst if REALLOC fails in, merge_words Date: Wed, 2 Sep 2020 15:20:29 +0800 Message-ID: References: <37544d4c-950f-4281-3b66-e4d1884c5167@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <37544d4c-950f-4281-3b66-e4d1884c5167@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: Martin Wilck , Benjamin Marzinski , Christophe Varoqui , dm-devel mailing list Cc: linfeilong , "liuzhiqiang (I)" List-Id: dm-devel.ids In merge_words func, if REALLOC() fails, the input *dst will be freed. If so, mpp->hwhandler| mpp->features|mpp->selector may be set to NULL after calling merge_words func in disassemble_map func. This may cause accessing freed memory problem. Here, we donot free *dst if REALLOC() fails in merge_words func. Signed-off-by: Zhiqiang Liu Signed-off-by: Lixiaokeng --- libmultipath/dmparser.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c index c1031616..482e9d0e 100644 --- a/libmultipath/dmparser.c +++ b/libmultipath/dmparser.c @@ -26,13 +26,12 @@ merge_words(char **dst, const char *word) dstlen = strlen(*dst); len = dstlen + strlen(word) + 2; - *dst = REALLOC(*dst, len); + p = REALLOC(*dst, len); - if (!*dst) { - free(p); + if (!p) return 1; - } + *dst = p; p = *dst + dstlen; *p = ' '; ++p; --