From patchwork Fri Nov 6 09:26:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 11886485 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31D3B6A2 for ; Fri, 6 Nov 2020 09:26:54 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F36D72087E for ; Fri, 6 Nov 2020 09:26:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F36D72087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9D9771674C0F1; Fri, 6 Nov 2020 01:26:53 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.191; helo=szxga05-in.huawei.com; envelope-from=liuzhiqiang26@huawei.com; receiver= Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3ACDA1674C0EF for ; Fri, 6 Nov 2020 01:26:50 -0800 (PST) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CSFQ942QbzLtmq for ; Fri, 6 Nov 2020 17:26:41 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 17:26:39 +0800 Subject: [ndctl PATCH 5/8] util/help: check whether strdup returns NULL in exec_man_konqueror To: References: From: Zhiqiang Liu Message-ID: <889d3dc7-2532-9f91-b0d8-5eeab45d6bb7@huawei.com> Date: Fri, 6 Nov 2020 17:26:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Message-ID-Hash: MS2AGY5AN4V7EAP275FP4TAMFWM6GOBG X-Message-ID-Hash: MS2AGY5AN4V7EAP275FP4TAMFWM6GOBG X-MailFrom: liuzhiqiang26@huawei.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: linux-nvdimm@lists.01.org, linfeilong , liuzhiqiang26@huawei.com X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: In exec_man_konqueror(), new is allocated by calling strdup(), which may return NULL. We should check whether new is NULL before using it. Signed-off-by: Zhiqiang Liu --- util/help.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util/help.c b/util/help.c index 2d57fa1..f867944 100644 --- a/util/help.c +++ b/util/help.c @@ -44,8 +44,14 @@ static void exec_man_konqueror(const char *path, const char *page) if (path) { const char *file = strrchr(path, '/'); if (file && !strcmp(file + 1, "konqueror")) { + char *dest; char *new = strdup(path); - char *dest = strrchr(new, '/'); + if (!new) { + pr_err("strdup(path) fails.\n"); + exit(1); + } + + dest = strrchr(new, '/'); /* strlen("konqueror") == strlen("kfmclient") */ strcpy(dest + 1, "kfmclient");