From 27952b11f736a7dc1fb4e27a1251481d4f71c751 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 8 Mar 2017 19:19:03 +0100 Subject: [PATCH 1/1] disk: sanitize trailing slashes fixes #200 --- src/print_disk_info.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 -- 2.39.2