From patchwork Sat Dec 10 13:47:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasanth KSR X-Patchwork-Id: 9469339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 41BD760231 for ; Sat, 10 Dec 2016 13:48:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 341112856A for ; Sat, 10 Dec 2016 13:48:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 293022859E; Sat, 10 Dec 2016 13:48:53 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 DD498285A1 for ; Sat, 10 Dec 2016 13:48:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932242AbcLJNsn (ORCPT ); Sat, 10 Dec 2016 08:48:43 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35264 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932146AbcLJNsW (ORCPT ); Sat, 10 Dec 2016 08:48:22 -0500 Received: by mail-pg0-f65.google.com with SMTP id p66so5385837pga.2 for ; Sat, 10 Dec 2016 05:48:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bZ7PnIkyr9h7YkEsH39GpqIin83cQJF/ZwwrrJR+WLM=; b=fpc2LhYV3k1GkRUa2Nto1iL65iWiSEn6jfJEu3pbkWTyupgcoqzWo69WiK1dL7sQWR 2w0hiAvCF1UUQW/PbKR0hm3z8dnIBEauyysgRJtU5i0IXk43s/08VJnL7kj8Tiv2uJ8z ehZhnI4l/8ZIrmEoL1Q1XovdqUW6baxpCn3sXu6fqG+4StXMBftTzzmVEIo38aUwqAZd 3wrYQLXcta8782joXA6LKeSrmBl/fVOj3XfTzeg3EM7TZoYowilzlj6QmgCFvdRbw296 t46hBmwCqvFk0ShHvV6h8vGHAzztYxJwzAb4V2XZwlSdrSLX+a9vTYz6ITS8Dj0Nbl+k hq1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bZ7PnIkyr9h7YkEsH39GpqIin83cQJF/ZwwrrJR+WLM=; b=IyPQwWm+JPuvj8MQ/Tswxax3GxxwzYOtZxIm0cAvFekv+s9xb5PqHutF3ZnZQWs+US IUT/Xy2ib4qWf0xEa8c3Dz7gZXtILXy2cBBj6nQOcFK5f/zf0FDUd2IkLyslPWriYZS2 wsUTw00DyKGRb6HJpIePvJV9ANe01PwuN3lAGuT1LT3Z4Hkx/789aIZB3isdBZqyeIz5 eq3IvRchHagWKMz6NKGs4IEEuAMDXJ4W9sIqWz1eCzEHdxN3AwwgrOV1LcCyImcNbzub TvWh6O06CRt8jcH5zm9daYs7aigtlGyA+qX4oAOffGng42xzVzWZLw/NuHuyl1uZCNSA Ww8A== X-Gm-Message-State: AKaTC0028Dt4apspFmCIlXAwC+Jp/O980qsSauBQNMQB+TlCzNJNgArtO6duBurAemHiLw== X-Received: by 10.99.150.10 with SMTP id c10mr85691201pge.121.1481377702056; Sat, 10 Dec 2016 05:48:22 -0800 (PST) Received: from linux.local ([122.167.185.200]) by smtp.gmail.com with ESMTPSA id w17sm65166394pgm.18.2016.12.10.05.48.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Dec 2016 05:48:21 -0800 (PST) From: Prasanth K S R To: linux-btrfs@vger.kernel.org Cc: Prasanth K S R , dsterba@suse.com Subject: [PATCH 3/3] Btrfs-progs: subvol_uuid_search: Return error code on memory allocation failure Date: Sat, 10 Dec 2016 19:17:44 +0530 Message-Id: <20161210134744.10825-3-kosigiprasanth@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161210134744.10825-1-kosigiprasanth@gmail.com> References: <20161210134744.10825-1-kosigiprasanth@gmail.com> 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: Prasanth K S R On failure of memory allocation for a 'struct subvol_info', we would end up dereferencing a NULL pointer. This commit fixes the issue by returning an error encoded pointer. Signed-off-by: Prasanth K S R --- send-utils.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/send-utils.c b/send-utils.c index 252ca6d..95445b5 100644 --- a/send-utils.c +++ b/send-utils.c @@ -474,6 +474,10 @@ struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s, goto out; info = calloc(1, sizeof(*info)); + if (!info) { + ret = -ENOMEM; + goto out; + } info->root_id = root_id; memcpy(info->uuid, root_item.uuid, BTRFS_UUID_SIZE); memcpy(info->received_uuid, root_item.received_uuid, BTRFS_UUID_SIZE); @@ -495,9 +499,11 @@ struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s, } out: - if (ret && info) { - free(info->path); - free(info); + if (ret) { + if (info) { + free(info->path); + free(info); + } return ERR_PTR(ret); }