mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
#3773: Check for errors around the use of PyTokenizer_FindEncoding().
reviewed by Brett Cannon.
This commit is contained in:
parent
1d6a16bf38
commit
1b933ed50a
3 changed files with 9 additions and 1 deletions
|
|
@ -12,6 +12,9 @@ What's New in Python 3.0 release candidate 1
|
||||||
Core and Builtins
|
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
|
- 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
|
tokenized by either a file path or file pointer for the benefit of
|
||||||
PyTokenizer_FindEncoding().
|
PyTokenizer_FindEncoding().
|
||||||
|
|
|
||||||
|
|
@ -1610,7 +1610,10 @@ PyTokenizer_FindEncoding(int fd)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (tok->encoding) {
|
if (tok->encoding) {
|
||||||
encoding = (char *)PyMem_MALLOC(strlen(tok->encoding) + 1);
|
encoding = (char *)PyMem_MALLOC(strlen(tok->encoding) + 1);
|
||||||
strcpy(encoding, tok->encoding);
|
if (encoding)
|
||||||
|
strcpy(encoding, tok->encoding);
|
||||||
|
else
|
||||||
|
PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
PyTokenizer_Free(tok);
|
PyTokenizer_Free(tok);
|
||||||
return encoding;
|
return encoding;
|
||||||
|
|
|
||||||
|
|
@ -2830,6 +2830,8 @@ call_find_module(char *name, PyObject *path)
|
||||||
memory. */
|
memory. */
|
||||||
found_encoding = PyTokenizer_FindEncoding(fd);
|
found_encoding = PyTokenizer_FindEncoding(fd);
|
||||||
lseek(fd, 0, 0); /* Reset position */
|
lseek(fd, 0, 0); /* Reset position */
|
||||||
|
if (found_encoding == NULL && PyErr_Occurred())
|
||||||
|
return NULL;
|
||||||
encoding = (found_encoding != NULL) ? found_encoding :
|
encoding = (found_encoding != NULL) ? found_encoding :
|
||||||
(char*)PyUnicode_GetDefaultEncoding();
|
(char*)PyUnicode_GetDefaultEncoding();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue