Skip to content

Commit 50983f8

Browse files
Generic decoding for mountpoints
#364
1 parent 5026be2 commit 50983f8

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/detection/disk/disk_linux.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
11
#include "disk.h"
22

3+
#include <limits.h>
34
#include <ctype.h>
45
#include <sys/statvfs.h>
56

67
static void strbufAppendMountPoint(FFstrbuf* mountpoint, const char* source)
78
{
89
while(*source != '\0' && !isspace(*source))
910
{
10-
//Backslash is encoded as \134
11-
if(strncmp(source, "\\134", 4) == 0)
11+
//After a backslash the next 3 characters are octal ascii codes
12+
if(*source == '\\' && strnlen(source, 4) == 4)
1213
{
13-
ffStrbufAppendC(mountpoint, '\\');
14-
source += 4;
15-
continue;
16-
}
17-
18-
//Space is encoded as \040
19-
if(strncmp(source, "\\040", 4) == 0)
20-
{
21-
ffStrbufAppendC(mountpoint, ' ');
22-
source += 4;
23-
continue;
24-
}
25-
26-
//Tab is encoded as \011
27-
if(strncmp(source, "\\011", 4) == 0)
28-
{
29-
ffStrbufAppendC(mountpoint, '\t');
30-
source += 4;
31-
continue;
14+
char octal[4] = {0};
15+
strncpy(octal, source + 1, 3);
16+
17+
long value = strtol(octal, NULL, 8); //Returns 0 on error, so no need to check endptr
18+
if(value > 0 && value < CHAR_MAX)
19+
{
20+
ffStrbufAppendC(mountpoint, (char) value);
21+
source += 4;
22+
continue;
23+
}
3224
}
3325

3426
ffStrbufAppendC(mountpoint, *source);

0 commit comments

Comments
 (0)