summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-03-27 08:55:07 +0100
committerJo-Philipp Wich <jo@mein.io>2019-03-31 16:09:40 +0200
commit9b36dc25dd31197681dfcbe4e83879a9b885f451 (patch)
treee32669cace3e9c173561fdb0a23e3e14dcb77d38
parentff1ded63c51e84e239fb422ac8b9d15251d1221f (diff)
downloadfstools-9b36dc25dd31197681dfcbe4e83879a9b885f451.tar.gz
libfstools: avoid false positives when matching devices and volumes
Revise matching code using strncmp() in order to avoid returning wrong items, e.g. /dev/sda1 when /dev/sda was requested. Ref: https://bugs.openwrt.org/index.php?do=details&task_id=2196 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--libfstools/find.c6
-rw-r--r--libfstools/ubi.c2
2 files changed, 4 insertions, 4 deletions
diff --git a/libfstools/find.c b/libfstools/find.c
index b383f57..cefdd23 100644
--- a/libfstools/find.c
+++ b/libfstools/find.c
@@ -23,6 +23,7 @@ int
find_overlay_mount(char *overlay)
{
FILE *fp = fopen("/proc/mounts", "r");
+ size_t len = strlen(overlay);
static char line[256];
int ret = -1;
@@ -30,7 +31,7 @@ find_overlay_mount(char *overlay)
return ret;
while (ret && fgets(line, sizeof(line), fp))
- if (!strncmp(line, overlay, strlen(overlay)))
+ if (len < sizeof(line) && !strncmp(line, overlay, len) && line[len] == ' ')
ret = 0;
fclose(fp);
@@ -103,7 +104,6 @@ find_mount_point(char *block, int root_only)
{
FILE *fp = fopen("/proc/self/mountinfo", "r");
static char line[256];
- int len = strlen(block);
char *point = NULL, *pos, *tmp, *cpoint, *devname, *fstype;
struct stat s;
int rstat;
@@ -183,7 +183,7 @@ find_mount_point(char *block, int root_only)
devname = tmp;
/* if device name matches */
- if (!strncmp(block, devname, len + 1)) {
+ if (!strcmp(block, devname)) {
if (root_only && fs_rootfs_only(fstype))
break;
diff --git a/libfstools/ubi.c b/libfstools/ubi.c
index f9d6e0a..091ccf6 100644
--- a/libfstools/ubi.c
+++ b/libfstools/ubi.c
@@ -147,7 +147,7 @@ static struct volume *ubi_volume_match(char *name, int ubi_num, int volid)
return NULL;
}
- if (strncmp(name, volname, strlen(volname) + 1))
+ if (strcmp(name, volname))
return NULL;
p = calloc(1, sizeof(struct ubi_volume));