]> arthur.barton.de Git - netdata.git/commitdiff
decode octal escaping found in /proc/self/mountinfo to escape mainly spaces; fixes...
authorCosta Tsaousis <costa@tsaousis.gr>
Wed, 20 Jul 2016 21:18:51 +0000 (00:18 +0300)
committerCosta Tsaousis <costa@tsaousis.gr>
Wed, 20 Jul 2016 21:18:51 +0000 (00:18 +0300)
src/proc_self_mountinfo.c

index 45630b4c0c3f7b1881b3b6e6d97d3a40cd27b3a4..303310a0ed323f872b3e525ffefa1cebed1bb932 100644 (file)
@@ -7,6 +7,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <ctype.h>
 
 #include "common.h"
 #include "log.h"
@@ -101,6 +102,35 @@ void mountinfo_free(struct mountinfo *mi) {
        free(mi);
 }
 
+static char *strdup_decoding_octal(const char *string) {
+       char *buffer = strdup(string);
+       if(!buffer) fatal("Cannot allocate memory.");
+
+       char *d = buffer;
+       const char *s = string;
+
+       while(*s) {
+               if(unlikely(*s == '\\')) {
+                       if(likely(isdigit(s[1]) && isdigit(s[2]) && isdigit(s[3]))) {
+                               char c = *s++ - '0';
+                               c <<= 3;
+                               c |= *s++ - '0';
+                               c <<= 3;
+                               c |= *s++ - '0';
+                               *d++ = c;
+                       }
+                       else {
+                               *d++ = '_';
+                               s++;
+                       }
+               }
+               else *d++ = *s++;
+       }
+       *d = '\0';
+
+       return buffer;
+}
+
 // read the whole mountinfo into a linked list
 struct mountinfo *mountinfo_read() {
        procfile *ff = NULL;
@@ -151,7 +181,7 @@ struct mountinfo *mountinfo_read() {
                if(unlikely(!mi->root)) fatal("Cannot allocate memory");
                mi->root_hash = simple_hash(mi->root);
 
-               mi->mount_point = strdup(procfile_lineword(ff, l, w)); w++;
+               mi->mount_point = strdup_decoding_octal(procfile_lineword(ff, l, w)); w++;
                if(unlikely(!mi->mount_point)) fatal("Cannot allocate memory");
                mi->mount_point_hash = simple_hash(mi->mount_point);