[Python-3000-checkins] r66224 - in python/branches/py3k: Misc/NEWS Parser/tokenizer.c Python/import.c

amaury.forgeotdarc python-3000-checkins at python.org
Fri Sep 5 00:34:09 CEST 2008


Author: amaury.forgeotdarc
Date: Fri Sep  5 00:34:09 2008
New Revision: 66224

Log:
#3773: Check for errors around the use of PyTokenizer_FindEncoding().

reviewed by Brett Cannon.


Modified:
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Parser/tokenizer.c
   python/branches/py3k/Python/import.c

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Fri Sep  5 00:34:09 2008
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue 3774: Added a few more checks in PyTokenizer_FindEncoding to handle
+  error conditions.
+
 - Issue 3594: Fix Parser/tokenizer.c:fp_setreadl() to open the file being
   tokenized by either a file path or file pointer for the benefit of
   PyTokenizer_FindEncoding().

Modified: python/branches/py3k/Parser/tokenizer.c
==============================================================================
--- python/branches/py3k/Parser/tokenizer.c	(original)
+++ python/branches/py3k/Parser/tokenizer.c	Fri Sep  5 00:34:09 2008
@@ -1610,7 +1610,10 @@
 	fclose(fp);
 	if (tok->encoding) {
             encoding = (char *)PyMem_MALLOC(strlen(tok->encoding) + 1);
-            strcpy(encoding, tok->encoding);
+            if (encoding)
+                strcpy(encoding, tok->encoding);
+            else
+                PyErr_NoMemory();
         }
 	PyTokenizer_Free(tok);
 	return encoding;

Modified: python/branches/py3k/Python/import.c
==============================================================================
--- python/branches/py3k/Python/import.c	(original)
+++ python/branches/py3k/Python/import.c	Fri Sep  5 00:34:09 2008
@@ -2830,6 +2830,8 @@
 			   memory. */
 			found_encoding = PyTokenizer_FindEncoding(fd);
 			lseek(fd, 0, 0); /* Reset position */
+			if (found_encoding == NULL && PyErr_Occurred())
+				return NULL;
 			encoding = (found_encoding != NULL) ? found_encoding :
 				   (char*)PyUnicode_GetDefaultEncoding();
 		}


More information about the Python-3000-checkins mailing list