decode octal escaping found in /proc/self/mountinfo to escape mainly spaces; fixes #715
Costa Tsaousis committed
Jul 21, 2016 at 00:18 UTC
ffe486a2093c29f54dd3113f99cdfcb2c08d952d
1 file changed
+31
-1
src/proc_self_mountinfo.c
+31
-1
@@ -7,6 +7,7 @@
7
#include <sys/types.h>
8
#include <sys/stat.h>
9
#include <fcntl.h>
10
+#include <ctype.h>
11
12
#include "common.h"
13
#include "log.h"
@@ -101,6 +102,35 @@ void mountinfo_free(struct mountinfo *mi) {
102
free(mi);
103
}
104
105
+static char *strdup_decoding_octal(const char *string) {
106
+ char *buffer = strdup(string);
107
+ if(!buffer) fatal("Cannot allocate memory.");
108
+
109
+ char *d = buffer;
110
+ const char *s = string;
111
+
112
+ while(*s) {
113
+ if(unlikely(*s == '\\')) {
114
+ if(likely(isdigit(s[1]) && isdigit(s[2]) && isdigit(s[3]))) {
115
+ char c = *s++ - '0';
116
+ c <<= 3;
117
+ c |= *s++ - '0';
118
+ c <<= 3;
119
+ c |= *s++ - '0';
120
+ *d++ = c;
121
+ }
122
+ else {
123
+ *d++ = '_';
124
+ s++;
125
+ }
126
+ }
127
+ else *d++ = *s++;
128
+ }
129
+ *d = '\0';
130
+
131
+ return buffer;
132
+}
133
+
134
// read the whole mountinfo into a linked list
135
struct mountinfo *mountinfo_read() {
136
procfile *ff = NULL;
@@ -151,7 +181,7 @@ struct mountinfo *mountinfo_read() {
181
if(unlikely(!mi->root)) fatal("Cannot allocate memory");
182
mi->root_hash = simple_hash(mi->root);
183
154
- mi->mount_point = strdup(procfile_lineword(ff, l, w)); w++;
184
+ mi->mount_point = strdup_decoding_octal(procfile_lineword(ff, l, w)); w++;
185
if(unlikely(!mi->mount_point)) fatal("Cannot allocate memory");
186
mi->mount_point_hash = simple_hash(mi->mount_point);
187