From: Michael Stapelberg Date: Wed, 8 Mar 2017 18:19:03 +0000 (+0100) Subject: disk: sanitize trailing slashes X-Git-Tag: 2.12~25^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=27952b11f736a7dc1fb4e27a1251481d4f71c751;hp=37e73e77b0514993cd386a5d12509c88dddba5ed;p=i3%2Fi3status disk: sanitize trailing slashes fixes #200 --- 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