summaryrefslogtreecommitdiff
path: root/src/print_disk_info.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2017-03-08 19:19:03 +0100
committerMichael Stapelberg <michael@stapelberg.de>2017-03-08 19:22:22 +0100
commit27952b11f736a7dc1fb4e27a1251481d4f71c751 (patch)
tree8b8fff8b05dfbab21a86e0ad5c481f674d110840 /src/print_disk_info.c
parent37e73e77b0514993cd386a5d12509c88dddba5ed (diff)
disk: sanitize trailing slashes
fixes #200
Diffstat (limited to 'src/print_disk_info.c')
-rw-r--r--src/print_disk_info.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/print_disk_info.c b/src/print_disk_info.c
index d343fb8..3be81ea 100644
--- a/src/print_disk_info.c
+++ b/src/print_disk_info.c
@@ -141,16 +141,20 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
* we consider the device not mounted. */
mounted = false;
} else {
+ char *sanitized = sstrdup(path);
+ if (sanitized[strlen(sanitized) - 1] == '/')
+ sanitized[strlen(sanitized) - 1] = '\0';
FILE *mntentfile = setmntent("/etc/mtab", "r");
struct mntent *m;
while ((m = getmntent(mntentfile)) != NULL) {
- if (strcmp(m->mnt_dir, path) == 0) {
+ if (strcmp(m->mnt_dir, sanitized) == 0) {
mounted = true;
break;
}
}
endmntent(mntentfile);
+ free(sanitized);
}
#endif