Skip to content

Commit

Permalink
python#3773: Check for errors around the use of PyTokenizer_FindEncod…
Browse files Browse the repository at this point in the history
…ing().

reviewed by Brett Cannon.
  • Loading branch information
amauryfa committed Sep 4, 2008
1 parent 1d6a16b commit 1b933ed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ What's New in Python 3.0 release candidate 1
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().
Expand Down
5 changes: 4 additions & 1 deletion Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,10 @@ PyTokenizer_FindEncoding(int fd)
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;
Expand Down
2 changes: 2 additions & 0 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -2830,6 +2830,8 @@ call_find_module(char *name, PyObject *path)
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();
}
Expand Down

0 comments on commit 1b933ed

Please sign in to comment.