[Python-checkins] cpython (3.2): Issue #9319: Fix a crash on parsing a Python source code without encoding
victor.stinner
python-checkins at python.org
Sat Apr 23 00:42:26 CEST 2011
http://hg.python.org/cpython/rev/fa5e348889c2
changeset: 69529:fa5e348889c2
branch: 3.2
parent: 69526:9f1767d680ff
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Sat Apr 23 00:41:19 2011 +0200
summary:
Issue #9319: Fix a crash on parsing a Python source code without encoding
cookie and not valid in UTF-8: use "<file>" as the filename instead of
reading from NULL.
files:
Lib/test/test_imp.py | 3 +++
Parser/tokenizer.c | 5 ++++-
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -170,6 +170,9 @@
support.unlink(init_file_name + ext)
support.rmtree(test_package_name)
+ def test_issue9319(self):
+ imp.find_module("test/badsyntax_pep3120")
+
class ReloadTests(unittest.TestCase):
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -586,7 +586,10 @@
if (badchar) {
/* Need to add 1 to the line number, since this line
has not been counted, yet. */
- filename = PyUnicode_DecodeFSDefault(tok->filename);
+ if (tok->filename != NULL)
+ filename = PyUnicode_DecodeFSDefault(tok->filename);
+ else
+ filename = PyUnicode_FromString("<file>");
if (filename != NULL) {
PyErr_Format(PyExc_SyntaxError,
"Non-UTF-8 code starting with '\\x%.2x' "
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list