1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| | /*
* Copyright (C) 2012-2016 all contributors <cmogstored-public@bogomips.org>
* License: GPLv3 or later (see COPYING for details)
*/
#include "cmogstored.h"
/*
* we could just use strstr(), but it's buggy on some glibc and
* we can expand this later (to tighten down to non-FIDs, for example)
*/
%%{
machine path_traversal;
main := any* ("..") @ { found = true; fbreak; } any*;
}%%
%% write data;
static bool path_traversal_found(const char *buf, size_t len)
{
const char *p, *pe;
bool found = false;
int cs;
%% write init;
p = buf;
pe = buf + len;
%% write exec;
return found;
}
int mog_valid_path(const char *buf, size_t len)
{
if (len >= MOG_PATH_MAX)
return 0;
return ! path_traversal_found(buf, len);
}
|