cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob 6ce592aeae7b32ec892c5738e3fcbcc7ca6eb43d 743 bytes (raw)
$ git show HEAD:valid_path.rl	# shows this blob on the CLI

 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-2020 all contributors <cmogstored-public@yhbt.net>
 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 */
#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);
}

git clone https://yhbt.net/cmogstored.git