[Python-Dev] unintentional and unsafe use of realpath()

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Sep 12 07:23:53 CEST 2005


Peter Jones wrote:

> Another problem (which I have not fixed) is that when realpath() is
> used, in some cases MAXPATHLEN is smaller than the system's
> PATH_MAX/pathconf(path, _PC_PATH_MAX).

The linux man page for realpath() has this at the bottom:

BUGS
        Never  use this function. It is broken by design since it is impossible
        to determine a suitable size for the output buffer.  According to POSIX
        a  buffer of size PATH_MAX suffices, but PATH_MAX need not be a defined
        constant, and may have to be obtained  using  pathconf().   And  asking
        pathconf() does not really help, since on the one hand POSIX warns that
        the result of pathconf() may be huge and unsuitable for mallocing  mem-
        ory.  And  on  the  other hand pathconf() may return -1 to signify that
        PATH_MAX is not bounded.

So maybe it shouldn't be using realpath() at all?

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list