public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: fdmanana@kernel.org
To: linux-btrfs@vger.kernel.org
Cc: ddis@suse.com, Filipe Manana <fdmanana@suse.com>
Subject: [PATCH 2/3] Btrfs-progs: add missing error handling in find_mount_root()
Date: Mon, 14 Jan 2019 13:31:34 +0000	[thread overview]
Message-ID: <20190114133134.18374-1-fdmanana@kernel.org> (raw)

From: Filipe Manana <fdmanana@suse.com>

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 <fdmanana@suse.com>
---
 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) {
-- 
2.11.0


             reply	other threads:[~2019-01-14 13:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-14 13:31 fdmanana [this message]
2019-01-14 14:02 ` [PATCH 2/3] Btrfs-progs: add missing error handling in find_mount_root() David Disseldorp

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=20190114133134.18374-1-fdmanana@kernel.org \
    --to=fdmanana@kernel.org \
    --cc=ddis@suse.com \
    --cc=fdmanana@suse.com \
    --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