cmogstored 1.8.1 - use default system stack size
[cmogstored.git] / valid_path.rl
blob6ce592aeae7b32ec892c5738e3fcbcc7ca6eb43d
1 /*
2  * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3  * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4  */
5 #include "cmogstored.h"
7 /*
8  * we could just use strstr(), but it's buggy on some glibc and
9  * we can expand this later (to tighten down to non-FIDs, for example)
10  */
11 %%{
12         machine path_traversal;
13         main := any* ("..") @ { found = true; fbreak; } any*;
14 }%%
16 %% write data;
18 static bool path_traversal_found(const char *buf, size_t len)
20         const char *p, *pe;
21         bool found = false;
22         int cs;
23         %% write init;
25         p = buf;
26         pe = buf + len;
27         %% write exec;
29         return found;
32 int mog_valid_path(const char *buf, size_t len)
34         if (len >= MOG_PATH_MAX)
35                 return 0;
37         return ! path_traversal_found(buf, len);