]> git.sur5r.net Git - i3/i3status/commitdiff
disk: sanitize trailing slashes 207/head
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 8 Mar 2017 18:19:03 +0000 (19:19 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 8 Mar 2017 18:22:22 +0000 (19:22 +0100)
fixes #200

src/print_disk_info.c

index d343fb89c1b94abe09271feb02a87da78c3235c1..3be81eaa604d409a75233bcf7963f97bd9f4b511 100644 (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