summaryrefslogtreecommitdiff
path: root/include_server
diff options
context:
space:
mode:
authorfergus.henderson <fergushenderson@users.noreply.github.com>2009-01-30 17:27:30 +0000
committerfergus.henderson <fergushenderson@users.noreply.github.com>2009-01-30 17:27:30 +0000
commiteb64edde28335724a446cef1e2c69c29fd98bbc1 (patch)
treeaa6764503b5d1c87601123a88be09f5df46cf4ba /include_server
parent29f6af3a97c70e5e3699510df48b34c0c7e8d18d (diff)
downloaddistcc-git-eb64edde28335724a446cef1e2c69c29fd98bbc1.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.
Diffstat (limited to 'include_server')
-rwxr-xr-xinclude_server/macro_eval.py7
-rwxr-xr-xinclude_server/parse_file.py4
2 files changed, 5 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*
$