block: prevent mount point confusion
authorJo-Philipp Wich <jo@mein.io>
Wed, 27 Mar 2019 07:59:02 +0000 (08:59 +0100)
committerJo-Philipp Wich <jo@mein.io>
Sun, 31 Mar 2019 14:09:40 +0000 (16:09 +0200)
Do not perform substring matches when identifying mount points to
avoid returning wrong entries, e.g. "/dev/mmcblk0p10" when
"/dev/mmcblk0p1" was requested.

Fixes: FS#2196
Ref: https://bugs.openwrt.org/index.php?do=details&task_id=2196
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
block.c

diff --git a/block.c b/block.c
index cfc87273ee9969a153a4beededc61a5c6ba40a16..39212d247fe46e07b4ea4113edf4687b59b7d4e7 100644 (file)
--- a/block.c
+++ b/block.c
@@ -579,7 +579,6 @@ static char* find_mount_point(char *block)
 {
        FILE *fp = fopen("/proc/self/mountinfo", "r");
        static char line[256];
-       int len = strlen(block);
        char *point = NULL, *pos, *tmp, *cpoint, *devname;
        struct stat s;
        int rstat;
@@ -643,7 +642,7 @@ static char* find_mount_point(char *block)
 
                *pos = '\0';
                devname = tmp;
-               if (!strncmp(block, devname, len)) {
+               if (!strcmp(block, devname)) {
                        point = strdup(cpoint);
                        break;
                }