disk: sanitize trailing slashes

fixes #200
This commit is contained in:
Michael Stapelberg 2017-03-08 19:19:03 +01:00
parent 37e73e77b0
commit 27952b11f7

View File

@ -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