Btrfs-progs: add missing error handling in find_mount_root()
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 Reviewed-by: David Disseldorp <ddiss@suse.de> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
cb8abddb20
commit
dc1c561250
8
utils.c
8
utils.c
|
@ -2062,7 +2062,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;
|
||||
|
@ -2085,12 +2085,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) {
|
||||
|
|
Loading…
Reference in New Issue