From: Eric Sandeen <sandeen@redhat.com>
To: David Sterba <dsterba@suse.cz>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 5/6] btrfs-progs: check allocation result in add_clone_source
Date: Fri, 19 Dec 2014 10:58:10 -0600 [thread overview]
Message-ID: <54945922.1050406@redhat.com> (raw)
In-Reply-To: <c95d6b73e37beb2e877ef36f0645f0b7269b27f7.1419005022.git.dsterba@suse.cz>
On 12/19/14 10:06 AM, David Sterba wrote:
> Resolves-Coverity-CID: 1054894
> Signed-off-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 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;
>
next prev parent reply other threads:[~2014-12-19 16:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-19 16:06 [PATCH 0/6] Btrfs progs, coverity fixes for 3.18 David Sterba
2014-12-19 16:06 ` [PATCH 1/6] btrfs-progs: corrupt block, add missing break to option I David Sterba
2014-12-19 16:49 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 2/6] btrfs-progs: corrupt block, add break after option U David Sterba
2014-12-19 16:49 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 3/6] btrfs-progs: fragments, close output file on error David Sterba
2014-12-19 16:50 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 4/6] btrfs-progs: check result of first_cache_extent David Sterba
2014-12-19 16:56 ` Eric Sandeen
2014-12-19 17:03 ` David Sterba
2014-12-19 16:06 ` [PATCH 5/6] btrfs-progs: check allocation result in add_clone_source David Sterba
2014-12-19 16:58 ` Eric Sandeen [this message]
2014-12-19 16:06 ` [PATCH 6/6] btrfs-progs: let btrfs_free_path accept NULL David Sterba
2014-12-19 16:58 ` Eric Sandeen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54945922.1050406@redhat.com \
--to=sandeen@redhat.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).