From f21034dfea0366f82709ed35c468add8f0e2c7f9 Mon Sep 17 00:00:00 2001 From: "Adam C. Foltzer" Date: Wed, 11 Oct 2017 09:14:14 -0700 Subject: add failing test case for overly-strict sandbox violation --- .../common/162 subproject dir name collision/a.c | 13 +++++++++++++ .../custom_subproject_dir/B/b.c | 20 ++++++++++++++++++++ .../custom_subproject_dir/B/meson.build | 4 ++++ .../custom_subproject_dir/C/c.c | 14 ++++++++++++++ .../custom_subproject_dir/C/meson.build | 2 ++ .../162 subproject dir name collision/meson.build | 12 ++++++++++++ .../other_subdir/custom_subproject_dir/other.c | 19 +++++++++++++++++++ .../other_subdir/meson.build | 1 + 8 files changed, 85 insertions(+) create mode 100644 test cases/common/162 subproject dir name collision/a.c create mode 100644 test cases/common/162 subproject dir name collision/custom_subproject_dir/B/b.c create mode 100644 test cases/common/162 subproject dir name collision/custom_subproject_dir/B/meson.build create mode 100644 test cases/common/162 subproject dir name collision/custom_subproject_dir/C/c.c create mode 100644 test cases/common/162 subproject dir name collision/custom_subproject_dir/C/meson.build create mode 100644 test cases/common/162 subproject dir name collision/meson.build create mode 100644 test cases/common/162 subproject dir name collision/other_subdir/custom_subproject_dir/other.c create mode 100644 test cases/common/162 subproject dir name collision/other_subdir/meson.build diff --git a/test cases/common/162 subproject dir name collision/a.c b/test cases/common/162 subproject dir name collision/a.c new file mode 100644 index 000000000..6ed96fa05 --- /dev/null +++ b/test cases/common/162 subproject dir name collision/a.c @@ -0,0 +1,13 @@ +#include +char func_b(); +char func_c(); + +int main(int argc, char **argv) { + if(func_b() != 'b') { + return 1; + } + if(func_c() != 'c') { + return 2; + } + return 0; +} diff --git a/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/b.c b/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/b.c new file mode 100644 index 000000000..4c94ee95f --- /dev/null +++ b/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/b.c @@ -0,0 +1,20 @@ +#include +char func_c(); + +#if defined _WIN32 || defined __CYGWIN__ +#define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +char DLL_PUBLIC func_b() { + if(func_c() != 'c') { + exit(3); + } + return 'b'; +} diff --git a/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/meson.build b/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/meson.build new file mode 100644 index 000000000..280c60ce2 --- /dev/null +++ b/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/meson.build @@ -0,0 +1,4 @@ +project('B', 'c') +C = subproject('C') +c = C.get_variable('c') +b = shared_library('b', 'b.c', link_with : c) diff --git a/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/c.c b/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/c.c new file mode 100644 index 000000000..eebfb9fba --- /dev/null +++ b/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/c.c @@ -0,0 +1,14 @@ +#if defined _WIN32 || defined __CYGWIN__ +#define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +char DLL_PUBLIC func_c() { + return 'c'; +} diff --git a/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/meson.build b/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/meson.build new file mode 100644 index 000000000..abf0b1e26 --- /dev/null +++ b/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/meson.build @@ -0,0 +1,2 @@ +project('C', 'c') +c = shared_library('c', 'c.c') diff --git a/test cases/common/162 subproject dir name collision/meson.build b/test cases/common/162 subproject dir name collision/meson.build new file mode 100644 index 000000000..55312175e --- /dev/null +++ b/test cases/common/162 subproject dir name collision/meson.build @@ -0,0 +1,12 @@ +project('A', 'c', subproject_dir:'custom_subproject_dir') + +B = subproject('B') +b = B.get_variable('b') + +C = subproject('C') +c = C.get_variable('c') + +subdir('other_subdir') + +a = executable('a', 'a.c', link_with : [b, c]) +test('a test', a) diff --git a/test cases/common/162 subproject dir name collision/other_subdir/custom_subproject_dir/other.c b/test cases/common/162 subproject dir name collision/other_subdir/custom_subproject_dir/other.c new file mode 100644 index 000000000..0c27f8431 --- /dev/null +++ b/test cases/common/162 subproject dir name collision/other_subdir/custom_subproject_dir/other.c @@ -0,0 +1,19 @@ +#include + +#if defined _WIN32 || defined __CYGWIN__ +#define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +char DLL_PUBLIC func_b() { + if('c' != 'c') { + exit(3); + } + return 'b'; +} diff --git a/test cases/common/162 subproject dir name collision/other_subdir/meson.build b/test cases/common/162 subproject dir name collision/other_subdir/meson.build new file mode 100644 index 000000000..90cb67a63 --- /dev/null +++ b/test cases/common/162 subproject dir name collision/other_subdir/meson.build @@ -0,0 +1 @@ +other = shared_library('other', 'custom_subproject_dir/other.c') -- cgit v1.2.3 From 53c1afffaf2833e6d1a29fa1df833e77e44841ec Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 29 Oct 2017 18:05:03 +0200 Subject: Evaluate subproject path correctly. Closes #2481. --- mesonbuild/interpreter.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 727c68851..52f178d47 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2799,6 +2799,16 @@ different subdirectory. super().run() mlog.log('Build targets in project:', mlog.bold(str(len(self.build.targets)))) + def evaluate_subproject_info(self, path_from_source_root, subproject_dirname): + depth = 0 + subproj_name = '' + segs = path_from_source_root.split(os.path.sep) + while segs and segs[0] == subproject_dirname: + depth += 1 + subproj_name = segs[1] + segs = segs[2:] + return (depth, subproj_name) + # Check that the indicated file is within the same subproject # as we currently are. This is to stop people doing # nasty things like: @@ -2820,17 +2830,16 @@ different subdirectory. return norm = os.path.relpath(norm, self.environment.source_dir) assert(not os.path.isabs(norm)) - segments = norm.split(os.path.sep) - num_sps = segments.count(self.subproject_dir) + (num_sps, sproj_name) = self.evaluate_subproject_info(norm, self.subproject_dir) + plain_filename = os.path.split(norm)[-1] if num_sps == 0: if self.subproject == '': return - raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % segments[-1]) + raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % plain_filename) if num_sps > 1: - raise InterpreterException('Sandbox violation: Tried to grab file %s from a nested subproject.' % segments[-1]) - sproj_name = segments[segments.index(self.subproject_dir) + 1] + raise InterpreterException('Sandbox violation: Tried to grab file %s from a nested subproject.' % plain_filename) if sproj_name != self.subproject_directory_name: - raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % segments[-1]) + raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % plain_filename) def source_strings_to_files(self, sources): results = [] -- cgit v1.2.3 From e8ed9754448efce129a7909d5aeade69609dadfb Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 29 Oct 2017 18:05:39 +0200 Subject: Renamed test dir to avoid duplicate numbers. --- .../common/162 subproject dir name collision/a.c | 13 ------------- .../custom_subproject_dir/B/b.c | 20 -------------------- .../custom_subproject_dir/B/meson.build | 4 ---- .../custom_subproject_dir/C/c.c | 14 -------------- .../custom_subproject_dir/C/meson.build | 2 -- .../162 subproject dir name collision/meson.build | 12 ------------ .../other_subdir/custom_subproject_dir/other.c | 19 ------------------- .../other_subdir/meson.build | 1 - .../common/163 subproject dir name collision/a.c | 13 +++++++++++++ .../custom_subproject_dir/B/b.c | 20 ++++++++++++++++++++ .../custom_subproject_dir/B/meson.build | 4 ++++ .../custom_subproject_dir/C/c.c | 14 ++++++++++++++ .../custom_subproject_dir/C/meson.build | 2 ++ .../163 subproject dir name collision/meson.build | 12 ++++++++++++ .../other_subdir/custom_subproject_dir/other.c | 19 +++++++++++++++++++ .../other_subdir/meson.build | 1 + 16 files changed, 85 insertions(+), 85 deletions(-) delete mode 100644 test cases/common/162 subproject dir name collision/a.c delete mode 100644 test cases/common/162 subproject dir name collision/custom_subproject_dir/B/b.c delete mode 100644 test cases/common/162 subproject dir name collision/custom_subproject_dir/B/meson.build delete mode 100644 test cases/common/162 subproject dir name collision/custom_subproject_dir/C/c.c delete mode 100644 test cases/common/162 subproject dir name collision/custom_subproject_dir/C/meson.build delete mode 100644 test cases/common/162 subproject dir name collision/meson.build delete mode 100644 test cases/common/162 subproject dir name collision/other_subdir/custom_subproject_dir/other.c delete mode 100644 test cases/common/162 subproject dir name collision/other_subdir/meson.build create mode 100644 test cases/common/163 subproject dir name collision/a.c create mode 100644 test cases/common/163 subproject dir name collision/custom_subproject_dir/B/b.c create mode 100644 test cases/common/163 subproject dir name collision/custom_subproject_dir/B/meson.build create mode 100644 test cases/common/163 subproject dir name collision/custom_subproject_dir/C/c.c create mode 100644 test cases/common/163 subproject dir name collision/custom_subproject_dir/C/meson.build create mode 100644 test cases/common/163 subproject dir name collision/meson.build create mode 100644 test cases/common/163 subproject dir name collision/other_subdir/custom_subproject_dir/other.c create mode 100644 test cases/common/163 subproject dir name collision/other_subdir/meson.build diff --git a/test cases/common/162 subproject dir name collision/a.c b/test cases/common/162 subproject dir name collision/a.c deleted file mode 100644 index 6ed96fa05..000000000 --- a/test cases/common/162 subproject dir name collision/a.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -char func_b(); -char func_c(); - -int main(int argc, char **argv) { - if(func_b() != 'b') { - return 1; - } - if(func_c() != 'c') { - return 2; - } - return 0; -} diff --git a/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/b.c b/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/b.c deleted file mode 100644 index 4c94ee95f..000000000 --- a/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/b.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -char func_c(); - -#if defined _WIN32 || defined __CYGWIN__ -#define DLL_PUBLIC __declspec(dllexport) -#else - #if defined __GNUC__ - #define DLL_PUBLIC __attribute__ ((visibility("default"))) - #else - #pragma message ("Compiler does not support symbol visibility.") - #define DLL_PUBLIC - #endif -#endif - -char DLL_PUBLIC func_b() { - if(func_c() != 'c') { - exit(3); - } - return 'b'; -} diff --git a/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/meson.build b/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/meson.build deleted file mode 100644 index 280c60ce2..000000000 --- a/test cases/common/162 subproject dir name collision/custom_subproject_dir/B/meson.build +++ /dev/null @@ -1,4 +0,0 @@ -project('B', 'c') -C = subproject('C') -c = C.get_variable('c') -b = shared_library('b', 'b.c', link_with : c) diff --git a/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/c.c b/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/c.c deleted file mode 100644 index eebfb9fba..000000000 --- a/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/c.c +++ /dev/null @@ -1,14 +0,0 @@ -#if defined _WIN32 || defined __CYGWIN__ -#define DLL_PUBLIC __declspec(dllexport) -#else - #if defined __GNUC__ - #define DLL_PUBLIC __attribute__ ((visibility("default"))) - #else - #pragma message ("Compiler does not support symbol visibility.") - #define DLL_PUBLIC - #endif -#endif - -char DLL_PUBLIC func_c() { - return 'c'; -} diff --git a/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/meson.build b/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/meson.build deleted file mode 100644 index abf0b1e26..000000000 --- a/test cases/common/162 subproject dir name collision/custom_subproject_dir/C/meson.build +++ /dev/null @@ -1,2 +0,0 @@ -project('C', 'c') -c = shared_library('c', 'c.c') diff --git a/test cases/common/162 subproject dir name collision/meson.build b/test cases/common/162 subproject dir name collision/meson.build deleted file mode 100644 index 55312175e..000000000 --- a/test cases/common/162 subproject dir name collision/meson.build +++ /dev/null @@ -1,12 +0,0 @@ -project('A', 'c', subproject_dir:'custom_subproject_dir') - -B = subproject('B') -b = B.get_variable('b') - -C = subproject('C') -c = C.get_variable('c') - -subdir('other_subdir') - -a = executable('a', 'a.c', link_with : [b, c]) -test('a test', a) diff --git a/test cases/common/162 subproject dir name collision/other_subdir/custom_subproject_dir/other.c b/test cases/common/162 subproject dir name collision/other_subdir/custom_subproject_dir/other.c deleted file mode 100644 index 0c27f8431..000000000 --- a/test cases/common/162 subproject dir name collision/other_subdir/custom_subproject_dir/other.c +++ /dev/null @@ -1,19 +0,0 @@ -#include - -#if defined _WIN32 || defined __CYGWIN__ -#define DLL_PUBLIC __declspec(dllexport) -#else - #if defined __GNUC__ - #define DLL_PUBLIC __attribute__ ((visibility("default"))) - #else - #pragma message ("Compiler does not support symbol visibility.") - #define DLL_PUBLIC - #endif -#endif - -char DLL_PUBLIC func_b() { - if('c' != 'c') { - exit(3); - } - return 'b'; -} diff --git a/test cases/common/162 subproject dir name collision/other_subdir/meson.build b/test cases/common/162 subproject dir name collision/other_subdir/meson.build deleted file mode 100644 index 90cb67a63..000000000 --- a/test cases/common/162 subproject dir name collision/other_subdir/meson.build +++ /dev/null @@ -1 +0,0 @@ -other = shared_library('other', 'custom_subproject_dir/other.c') diff --git a/test cases/common/163 subproject dir name collision/a.c b/test cases/common/163 subproject dir name collision/a.c new file mode 100644 index 000000000..6ed96fa05 --- /dev/null +++ b/test cases/common/163 subproject dir name collision/a.c @@ -0,0 +1,13 @@ +#include +char func_b(); +char func_c(); + +int main(int argc, char **argv) { + if(func_b() != 'b') { + return 1; + } + if(func_c() != 'c') { + return 2; + } + return 0; +} diff --git a/test cases/common/163 subproject dir name collision/custom_subproject_dir/B/b.c b/test cases/common/163 subproject dir name collision/custom_subproject_dir/B/b.c new file mode 100644 index 000000000..4c94ee95f --- /dev/null +++ b/test cases/common/163 subproject dir name collision/custom_subproject_dir/B/b.c @@ -0,0 +1,20 @@ +#include +char func_c(); + +#if defined _WIN32 || defined __CYGWIN__ +#define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +char DLL_PUBLIC func_b() { + if(func_c() != 'c') { + exit(3); + } + return 'b'; +} diff --git a/test cases/common/163 subproject dir name collision/custom_subproject_dir/B/meson.build b/test cases/common/163 subproject dir name collision/custom_subproject_dir/B/meson.build new file mode 100644 index 000000000..280c60ce2 --- /dev/null +++ b/test cases/common/163 subproject dir name collision/custom_subproject_dir/B/meson.build @@ -0,0 +1,4 @@ +project('B', 'c') +C = subproject('C') +c = C.get_variable('c') +b = shared_library('b', 'b.c', link_with : c) diff --git a/test cases/common/163 subproject dir name collision/custom_subproject_dir/C/c.c b/test cases/common/163 subproject dir name collision/custom_subproject_dir/C/c.c new file mode 100644 index 000000000..eebfb9fba --- /dev/null +++ b/test cases/common/163 subproject dir name collision/custom_subproject_dir/C/c.c @@ -0,0 +1,14 @@ +#if defined _WIN32 || defined __CYGWIN__ +#define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +char DLL_PUBLIC func_c() { + return 'c'; +} diff --git a/test cases/common/163 subproject dir name collision/custom_subproject_dir/C/meson.build b/test cases/common/163 subproject dir name collision/custom_subproject_dir/C/meson.build new file mode 100644 index 000000000..abf0b1e26 --- /dev/null +++ b/test cases/common/163 subproject dir name collision/custom_subproject_dir/C/meson.build @@ -0,0 +1,2 @@ +project('C', 'c') +c = shared_library('c', 'c.c') diff --git a/test cases/common/163 subproject dir name collision/meson.build b/test cases/common/163 subproject dir name collision/meson.build new file mode 100644 index 000000000..55312175e --- /dev/null +++ b/test cases/common/163 subproject dir name collision/meson.build @@ -0,0 +1,12 @@ +project('A', 'c', subproject_dir:'custom_subproject_dir') + +B = subproject('B') +b = B.get_variable('b') + +C = subproject('C') +c = C.get_variable('c') + +subdir('other_subdir') + +a = executable('a', 'a.c', link_with : [b, c]) +test('a test', a) diff --git a/test cases/common/163 subproject dir name collision/other_subdir/custom_subproject_dir/other.c b/test cases/common/163 subproject dir name collision/other_subdir/custom_subproject_dir/other.c new file mode 100644 index 000000000..0c27f8431 --- /dev/null +++ b/test cases/common/163 subproject dir name collision/other_subdir/custom_subproject_dir/other.c @@ -0,0 +1,19 @@ +#include + +#if defined _WIN32 || defined __CYGWIN__ +#define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +char DLL_PUBLIC func_b() { + if('c' != 'c') { + exit(3); + } + return 'b'; +} diff --git a/test cases/common/163 subproject dir name collision/other_subdir/meson.build b/test cases/common/163 subproject dir name collision/other_subdir/meson.build new file mode 100644 index 000000000..90cb67a63 --- /dev/null +++ b/test cases/common/163 subproject dir name collision/other_subdir/meson.build @@ -0,0 +1 @@ +other = shared_library('other', 'custom_subproject_dir/other.c') -- cgit v1.2.3