Skip to content
  • Mike Fleetwood's avatar
    Use realpath() safely (#764369) · d04826cc
    Mike Fleetwood authored and Curtis Gedak's avatar Curtis Gedak committed
    realpath(3) manual page says:
    
        BUGS
            The POSIX.1-2001 standard version of this function is broken by
            design, since it is impossible to determine a suitable size for
            the output buffer, resolved_path.  According to POSIX.1-2001 a
            buffer of size PATH_MAX suffices, but PATH_MAX need not be a
            defined constant, and may have to be obtained using pathconf(3).
            And asking pathconf(3) does not really help, since, on the one
            hand POSIX warns that the result of pathconf(3) may be huge and
            unsuitable for mallocing memory, and on the other hand
            pathconf(3) may return -1 to signify that PATH_MAX is not
            bounded.  The resolved_path == NULL feature, not standardized in
            POSIX.1-2001, but standardized in POSIX.1-2008, allows this
            design problem to be avoided.
    
    The resolved_path == NULL feature of realpath() has existed as a Glibc
    extension since realpath() was first added to Glibc 1.90, released in
    June 1996.  Therefore it can be used unconditionally.
    
        https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=fa0bc87c32d02cd81ec4d0ae00e0d943c683e6e1
    
    Bug 764369 - Use realpath() safely
    d04826cc