diff options
author | fergus.henderson <fergus.henderson@01de4be4-8c4a-0410-9132-4925637da917> | 2009-01-30 17:27:30 +0000 |
---|---|---|
committer | fergus.henderson <fergus.henderson@01de4be4-8c4a-0410-9132-4925637da917> | 2009-01-30 17:27:30 +0000 |
commit | fba6586a129bba97a9ba0ece0a26f52ae35c4475 (patch) | |
tree | aa6764503b5d1c87601123a88be09f5df46cf4ba | |
parent | 6d2c05886957f0ae397996fb9cb07c7b57197bc9 (diff) | |
download | distcc-fba6586a129bba97a9ba0ece0a26f52ae35c4475.tar.gz |
Fix issue 35 <http://code.google.com/p/distcc/issues/detail?id=35>.
This was a bug where the include server was crashing in certain cases
(when the argument to a macro ended in a backslash) due to an escaping
problem in the use of Python's re.sub() function. The fix was to
replace all occurrences of backslash in the replacement string
with double-backslash, which re.sub() will then translate back to
a single backslash. (I also changed the code to not bother using
re.compile() since we only use the regexp once.)
Also, fix a bug where we were not allowing backslashes in filenames.
I added regression tests for both of these bugs
(and I verified that they were true regression tests).
Reviewed by Craig Silverstein.
git-svn-id: http://distcc.googlecode.com/svn/trunk@657 01de4be4-8c4a-0410-9132-4925637da917
-rwxr-xr-x | include_server/macro_eval.py | 7 | ||||
-rwxr-xr-x | include_server/parse_file.py | 4 | ||||
-rwxr-xr-x | test/testdistcc.py | 64 |
3 files changed, 69 insertions, 6 deletions
diff --git a/include_server/macro_eval.py b/include_server/macro_eval.py index f511b17..1c20a56 100755 --- a/include_server/macro_eval.py +++ b/include_server/macro_eval.py @@ -166,10 +166,9 @@ def _SubstituteSymbolInString(x, y, str): Debug(DEBUG_TRACE2, """_SubstituteSymbolInString: x: "%s", y: "%s", str:"%s" """, x, y, str) - sub_re = re.compile(r"\b%s\b" % re.escape(x)) - Debug(DEBUG_TRACE2, - """_SubstituteSymbolInString (result): "%s" """, sub_re.sub(y, str)) - return sub_re.sub(y, str) + result = re.sub(r"\b%s\b" % re.escape(x), y.replace('\\', '\\\\'), str) + Debug(DEBUG_TRACE2, """_SubstituteSymbolInString (result): "%s" """, result) + return result def _ParseArgs(string, pos): """Split stuff according to commas at outer level in parenthesized string. diff --git a/include_server/parse_file.py b/include_server/parse_file.py index 7558b69..bc6374e 100755 --- a/include_server/parse_file.py +++ b/include_server/parse_file.py @@ -111,8 +111,8 @@ DIRECTIVE_RE = re.compile(r""" INCLUDE_STRING_RE = re.compile(r""" ^ \s* - ( "\s*(?P<quote> (\w|[_/.+-])*)\s*" | - <\s*(?P<angle> (\w|[_/.+-])*)\s*> + ( "\s*(?P<quote> (\w|[\\_/.+-])*)\s*" | + <\s*(?P<angle> (\w|[\\_/.+-])*)\s*> ) \s* $ diff --git a/test/testdistcc.py b/test/testdistcc.py index 87b3820..c9aa23c 100755 --- a/test/testdistcc.py +++ b/test/testdistcc.py @@ -956,6 +956,67 @@ int main(void) { self.assert_equal(msgs, "hello world\n") +class ComputedInclude_Case(CompileHello_Case): + + def source(self): + return """ +#include <stdio.h> +#define MAKE_HEADER(header_name) STRINGIZE(header_name.h) +#define STRINGIZE(x) STRINGIZE2(x) +#define STRINGIZE2(x) #x +#define HEADER MAKE_HEADER(testhdr) +#include HEADER +int main(void) { + puts(HELLO_WORLD); + return 0; +} +""" + +class BackslashInMacro_Case(ComputedInclude_Case): + def source(self): + return """ +#if FALSE + #include <stdio.h> + #define HEADER MAKE_HEADER(testhdr) + #define MAKE_HEADER(header_name) STRINGIZE(foobar\) + #define STRINGIZE(x) STRINGIZE2(x) + #define STRINGIZE2(x) #x +#else + #define HEADER "testhdr.h" +#endif +#include HEADER +int main(void) { + puts(HELLO_WORLD); + return 0; +} +""" + +class BackslashInFilename_Case(ComputedInclude_Case): + + def headerFilename(self): + # On Windows, this filename will be in a subdirectory. + # On Unix, it will be a filename with an embedded backslash. + try: + os.mkdir("subdir") + except: + pass + return 'subdir\\testhdr.h' + + def source(self): + return """ +#include <stdio.h> +#define HEADER MAKE_HEADER(testhdr) +#define MAKE_HEADER(header_name) STRINGIZE(subdir\header_name.h) +#define STRINGIZE(x) STRINGIZE2(x) +#define STRINGIZE2(x) #x +#include HEADER +int main(void) { + puts(HELLO_WORLD); + return 0; +} +""" + + class LanguageSpecific_Case(Compilation_Case): """Abstract base class to test building non-C programs.""" def runtest(self): @@ -2048,6 +2109,9 @@ for path in os.environ['PATH'].split (':'): # All the tests defined in this suite tests = [ CompileHello_Case, + ComputedInclude_Case, + BackslashInMacro_Case, + BackslashInFilename_Case, CPlusPlus_Case, ObjectiveC_Case, ObjectiveCPlusPlus_Case, |