[Patches] trailing backslash breaks os.stat

Brian Hooper brian@garage.co.jp
Tue, 18 Apr 2000 02:13:32 GMT


This is a multi-part message in MIME format.

------=_NextPart_000_1bdd1a90_126466dd$11a6c204
Content-Type: text/plain; format=flowed

posixmodule's posix_do_stat simply calls the underlying OS's stat
function, so it's really the underlying OS's fault, but a trailing
backslash in the path on a call to os.stat on NT returns an error
rather than the file info; this seems inconsistent with stat on
other platforms, where a trailing forward slash is OK.  A dos
'dir \temp\' with a trailing backslash, for example, also works, but
stat on that same directory will fail.

A path which is too long will also blow up the library call.

The patch attempts to correct the above two issues.  The patch was
written by Don Bennett (dpb@infoseek.com), and only tweaked by me.

--Brian Hooper

----

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

------=_NextPart_000_1bdd1a90_126466dd$11a6c204
Content-Type: text/plain; name="posixmodule.patch.txt"; format=flowed
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="posixmodule.patch.txt"

*** Modules/posixmodule.c       Thu Apr 13 08:20:40 2000
--- Modules.new/posixmodule.c   Mon Apr 17 16:09:09 2000
***************
*** 549,556 ****
--- 549,577 ----
        struct stat st;
        char *path;
        int res;
+
+ #ifdef MS_WIN32
+       int pathlen;
+ #endif /* MS_WIN32 */
+
        if (!PyArg_ParseTuple(args, format, &path))
                return NULL;
+
+ #ifdef MS_WIN32
+       pathlen = strlen(path);
+       /* the library call can blow up if the file name is too long! */
+       if (pathlen > MAX_PATH) {
+           errno = ENAMETOOLONG;
+           return posix_error();
+       }
+
+       if (!((pathlen==3) && (path[1] == ':') && (path[2] == '\\'))) {
+           if ((pathlen > 0) && (path[pathlen-1] == '\\')) {
+               path[pathlen-1] = 0; /* nuke the trailing backslash */
+           }
+       }
+ #endif /* MS_WIN32 */
+
        Py_BEGIN_ALLOW_THREADS
        res = (*statfunc)(path, &st);
        Py_END_ALLOW_THREADS

------=_NextPart_000_1bdd1a90_126466dd$11a6c204--