Christian Heimes added the comment:
Fixed patch. Georg pointed out that PyArg_ParseTuple("s") returns a
reference to the internal data of the PyString object. The new version
copies the path to a fixed width buffer before it mangles the trailing
slashes.
The new patch applies against the trunk.
Brett, you are the import master. Can you review the patch, please?
----------
assignee: -> brett.cannon
nosy: +brett.cannon
Added file: http://bugs.python.org/file8675/trailing_slash2.patch
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1293>
__________________________________
Index: Python/import.c
===================================================================
--- Python/import.c (Revision 58750)
+++ Python/import.c (Arbeitskopie)
@@ -2978,23 +2978,45 @@
NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
{
char *path;
+ Py_ssize_t pathlen;
if (!_PyArg_NoKeywords("NullImporter()", kwds))
return -1;
- if (!PyArg_ParseTuple(args, "s:NullImporter",
- &path))
+ if (!PyArg_ParseTuple(args, "s#:NullImporter",
+ &path, &pathlen))
return -1;
- if (strlen(path) == 0) {
+ if (pathlen == 0) {
PyErr_SetString(PyExc_ImportError, "empty pathname");
return -1;
} else {
#ifndef RISCOS
struct stat statbuf;
int rv;
+ char mangled[MAXPATHLEN+1];
+ Py_ssize_t i;
- rv = stat(path, &statbuf);
+ if (pathlen > MAXPATHLEN) {
+ PyErr_SetString(PyExc_OverflowError,
+ "path is too long");
+ return -1;
+ }
+ strcpy(mangled, path);
+
+ /* Remove trailing / and \. Windows' stat doesn't like them */
+ for (i = pathlen-1; i > 0; i--) {
+#ifdef MS_WINDOWS
+ if (mangled[i] != '/' && mangled[i] != '\\') {
+#else
+ if (mangled[i] != '/') {
+#endif
+ break;
+ }
+ mangled[i] = '\0';
+ }
+
+ rv = stat(mangled, &statbuf);
if (rv == 0) {
/* it exists */
if (S_ISDIR(statbuf.st_mode)) {
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com