From: Zach Brown <zab@redhat.com>
To: Stefan Behrens <sbehrens@giantdisaster.de>
Cc: linux-btrfs@vger.kernel.org, Eric Sandeen <sandeen@redhat.com>,
David Sterba <dsterba@suse.cz>
Subject: Re: [PATCH 02/12] btrfs-progs: check fopen failure in cmds-send
Date: Tue, 8 Oct 2013 10:19:38 -0700 [thread overview]
Message-ID: <20131008171938.GL25712@lenny.home.zabbo.net> (raw)
In-Reply-To: <5253C552.7080609@giantdisaster.de>
> > @@ -72,6 +72,11 @@ int find_mount_root(const char *path, char **mount_root)
> > close(fd);
> >
> > mnttab = fopen("/proc/mounts", "r");
> > + if (!mnttab) {
> > + close(fd);
> > + return -errno;
>
> close() can modify errno.
>
> And close(fd) is already called 4 lines above. You didn't run the static
> code analysis again after applying your patch :)
OK, here's a less dumb attempt:
- z
>From f8a3425c184a55e0c254143e520e60a6856c27da Mon Sep 17 00:00:00 2001
From: Zach Brown <zab@redhat.com>
Date: Fri, 4 Oct 2013 15:38:18 -0700
Subject: [PATCH] btrfs-progs: check fopen failure in cmds-send
Check for fopen() failure. This shows up in static analysis as a
possible null pointer derference.
Signed-off-by: Zach Brown <zab@redhat.com>
Laughed-at-by: Stefan Behrens <sbehrens@giantdisaster.de>
---
cmds-send.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/cmds-send.c b/cmds-send.c
index 374d040..81b3e49 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -72,6 +72,9 @@ int find_mount_root(const char *path, char **mount_root)
close(fd);
mnttab = fopen("/proc/mounts", "r");
+ if (!mnttab)
+ return -errno;
+
while ((ent = getmntent(mnttab))) {
len = strlen(ent->mnt_dir);
if (strncmp(ent->mnt_dir, path, len) == 0) {
--
1.7.11.7
next prev parent reply other threads:[~2013-10-08 17:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-07 21:42 [RFC] another round of static analysis fixes Zach Brown
2013-10-07 21:42 ` [PATCH 01/12] btrfs-progs: check path alloc in corrupt block Zach Brown
2013-10-07 21:42 ` [PATCH 02/12] btrfs-progs: check fopen failure in cmds-send Zach Brown
2013-10-08 8:41 ` Stefan Behrens
2013-10-08 16:44 ` Zach Brown
2013-10-08 17:19 ` Zach Brown [this message]
2013-10-07 21:42 ` [PATCH 03/12] btrfs-progs: don't overrun name in find-collisions Zach Brown
2013-10-07 21:42 ` [PATCH 04/12] btrfs-progs: don't overflow read buffer in image Zach Brown
2013-10-07 21:42 ` [PATCH 05/12] btrfs-progs: check link_subvol name base Zach Brown
2013-10-07 21:42 ` [PATCH 06/12] btrfs-progs: remove dead block group checking Zach Brown
2013-10-07 21:43 ` [PATCH 07/12] btrfs-progs: free eb in fixup_chunk_tree_block() Zach Brown
2013-10-07 21:43 ` [PATCH 08/12] btrfs-progs: don't leak path in verify_space_cache Zach Brown
2013-10-08 5:18 ` chandan
2013-10-07 21:43 ` [PATCH 09/12] btrfs-progs: don't deref pipefd[-1] Zach Brown
2013-10-07 21:45 ` Eric Sandeen
2013-10-07 21:47 ` Zach Brown
2013-10-07 21:43 ` [PATCH 10/12] btrfs-progs: don't overflow colors[] in fragments Zach Brown
2013-10-07 21:43 ` [PATCH 11/12] btrfs-progs: remove unused variables Zach Brown
2013-10-07 21:43 ` [PATCH 12/12] btrfs-progs: free leaked roots in calc-size Zach Brown
2013-10-08 16:38 ` [RFC] another round of static analysis fixes David Sterba
2013-10-08 17:20 ` Zach Brown
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=20131008171938.GL25712@lenny.home.zabbo.net \
--to=zab@redhat.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=sbehrens@giantdisaster.de \
/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).