All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] Btrfs-progs: add missing error handling in find_mount_root()
@ 2019-01-14 13:31 fdmanana
  2019-01-14 14:02 ` David Disseldorp
  0 siblings, 1 reply; 2+ messages in thread
From: fdmanana @ 2019-01-14 13:31 UTC (permalink / raw)
  To: linux-btrfs; +Cc: ddis, Filipe Manana

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/3] Btrfs-progs: add missing error handling in find_mount_root()
  2019-01-14 13:31 [PATCH 2/3] Btrfs-progs: add missing error handling in find_mount_root() fdmanana
@ 2019-01-14 14:02 ` David Disseldorp
  0 siblings, 0 replies; 2+ messages in thread
From: David Disseldorp @ 2019-01-14 14:02 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs, Filipe Manana

On Mon, 14 Jan 2019 13:31:34 +0000, fdmanana@kernel.org wrote:

> 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(-)

Looks good:
Reviewed-by: David Disseldorp <ddiss@suse.de>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-14 14:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-14 13:31 [PATCH 2/3] Btrfs-progs: add missing error handling in find_mount_root() fdmanana
2019-01-14 14:02 ` David Disseldorp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.