summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-05-08 09:46:11 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-05-08 15:18:24 +0200
commitba647f63f0d7a005c66821ace650a5ee170a7370 (patch)
tree471edab327eebf434ab2d628b05058220ad60d7f
parent17c0fe184d2cb6a1c76f49d4e98a3b5a3edc735b (diff)
downloadbarebox-ba647f63f0d7a005c66821ace650a5ee170a7370.tar.gz
fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath
get_fsdevice_by_path will return NULL if no file system was mounted at location. Returned pointer was dereferenced unconditionally, potentially leading to null pointer dereference. Fix this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230508074612.3313870-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--fs/fs.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 65e4c661b9..368458cc54 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -240,6 +240,8 @@ struct cdev *get_cdev_by_mountpath(const char *path)
struct fs_device *fsdev;
fsdev = get_fsdevice_by_path(path);
+ if (!fsdev)
+ return NULL;
return fsdev->cdev;
}
@@ -249,6 +251,8 @@ char *get_mounted_path(const char *path)
struct fs_device *fdev;
fdev = get_fsdevice_by_path(path);
+ if (!fdev)
+ return NULL;
return fdev->path;
}