From patchwork Mon Jan 14 13:31:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10762539 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 676596C2 for ; Mon, 14 Jan 2019 13:31:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5856428BB6 for ; Mon, 14 Jan 2019 13:31:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49B7928BBE; Mon, 14 Jan 2019 13:31:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C26F228BA8 for ; Mon, 14 Jan 2019 13:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726579AbfANNbj (ORCPT ); Mon, 14 Jan 2019 08:31:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:58838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbfANNbj (ORCPT ); Mon, 14 Jan 2019 08:31:39 -0500 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2EEBE20651; Mon, 14 Jan 2019 13:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547472699; bh=1IgkYnH4NoPBt1CFSxWMIPgb+d8cbnUnbUnanGk77hY=; h=From:To:Cc:Subject:Date:From; b=KaZqizlyegcdvuXuytcjStthytD6QPNFDp2RFSj7y73YhrzgAxn+HSei2ccpznzwI iG73fxxnWcp273v7lt0Bq37p62CE+rVHH40rco0QoiIOJvpa6zszlPQDy9AlQZBLe4 30sEtYRgY4sy4o96z43AGh+0ANnWlVVcsKCG1wGY= From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Cc: ddis@suse.com, Filipe Manana Subject: [PATCH 2/3] Btrfs-progs: add missing error handling in find_mount_root() Date: Mon, 14 Jan 2019 13:31:34 +0000 Message-Id: <20190114133134.18374-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana The strdup() function can fail, in which case it returns NULL and sets errno [1]. Therefore add the missing error check after calling strdup() at find_mount_root(). [1] - http://man7.org/linux/man-pages/man3/strdup.3p.html Signed-off-by: Filipe Manana Reviewed-by: David Disseldorp --- utils.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils.c b/utils.c index 6616630b..3bc6bc3b 100644 --- a/utils.c +++ b/utils.c @@ -2048,7 +2048,7 @@ int find_mount_root(const char *path, char **mount_root) int fd; struct mntent *ent; int len; - int ret; + int ret = 0; int not_btrfs = 1; int longest_matchlen = 0; char *longest_match = NULL; @@ -2071,12 +2071,18 @@ int find_mount_root(const char *path, char **mount_root) free(longest_match); longest_matchlen = len; longest_match = strdup(ent->mnt_dir); + if (!longest_match) { + ret = -errno; + break; + } not_btrfs = strcmp(ent->mnt_type, "btrfs"); } } } endmntent(mnttab); + if (ret) + return ret; if (!longest_match) return -ENOENT; if (not_btrfs) {