From patchwork Fri Dec 19 16:06:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 5520591 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A94B3BEEA8 for ; Fri, 19 Dec 2014 16:06:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3A32D2013A for ; Fri, 19 Dec 2014 16:06:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48F5B20121 for ; Fri, 19 Dec 2014 16:06:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751762AbaLSQGk (ORCPT ); Fri, 19 Dec 2014 11:06:40 -0500 Received: from cantor2.suse.de ([195.135.220.15]:43119 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751355AbaLSQGj (ORCPT ); Fri, 19 Dec 2014 11:06:39 -0500 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CA2FEAC19 for ; Fri, 19 Dec 2014 16:06:38 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 4B760DAA27; Fri, 19 Dec 2014 17:06:38 +0100 (CET) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 5/6] btrfs-progs: check allocation result in add_clone_source Date: Fri, 19 Dec 2014 17:06:38 +0100 Message-Id: X-Mailer: git-send-email 2.1.3 In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Resolves-Coverity-CID: 1054894 Signed-off-by: David Sterba Reviewed-by: Eric Sandeen --- cmds-send.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/cmds-send.c b/cmds-send.c index b17b5e2ca666..9b32c1f0e624 100644 --- a/cmds-send.c +++ b/cmds-send.c @@ -172,11 +172,16 @@ out: return ret; } -static void add_clone_source(struct btrfs_send *s, u64 root_id) +static int add_clone_source(struct btrfs_send *s, u64 root_id) { s->clone_sources = realloc(s->clone_sources, sizeof(*s->clone_sources) * (s->clone_sources_count + 1)); + + if (!s->clone_sources) + return -ENOMEM; s->clone_sources[s->clone_sources_count++] = root_id; + + return 0; } static int write_buf(int fd, const void *buf, int size) @@ -475,7 +480,11 @@ int cmd_send(int argc, char **argv) goto out; } - add_clone_source(&send, root_id); + ret = add_clone_source(&send, root_id); + if (ret < 0) { + fprintf(stderr, "ERROR: not enough memory\n"); + goto out; + } subvol_uuid_search_finit(&send.sus); free(subvol); subvol = NULL; @@ -575,7 +584,11 @@ int cmd_send(int argc, char **argv) goto out; } - add_clone_source(&send, parent_root_id); + ret = add_clone_source(&send, parent_root_id); + if (ret < 0) { + fprintf(stderr, "ERROR: not enough memory\n"); + goto out; + } } for (i = optind; i < argc; i++) { @@ -671,7 +684,11 @@ int cmd_send(int argc, char **argv) goto out; /* done with this subvol, so add it to the clone sources */ - add_clone_source(&send, root_id); + ret = add_clone_source(&send, root_id); + if (ret < 0) { + fprintf(stderr, "ERROR: not enough memory\n"); + goto out; + } parent_root_id = 0; full_send = 0;