Index: Parser/tokenizer.c =================================================================== --- Parser/tokenizer.c (revision 83725) +++ Parser/tokenizer.c (working copy) @@ -580,6 +580,10 @@ } } if (badchar) { + /* Sending a NULL argument to PyErr_Format causes + a segfault. */ + if (tok->filename == NULL) + tok->filename = ""; /* Need to add 1 to the line number, since this line has not been counted, yet. */ PyErr_Format(PyExc_SyntaxError, Index: Lib/test/test_imp.py =================================================================== --- Lib/test/test_imp.py (revision 83725) +++ Lib/test/test_imp.py (working copy) @@ -62,6 +62,11 @@ self.assertEqual(fp.readline(), '"""Tokenization help for Python programs.\n') fp.close() + + def test_issue9319(self): + def _test(): + fp, filename, info = imp.find_module("badsyntax_pep3120") + self.assertRaises(SyntaxError, _test) def test_issue3594(self): temp_mod_name = 'test_imp_helper'