bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getcwd PATH_MAX limitation: shouldn't it fail?


From: Jim Meyering
Subject: getcwd PATH_MAX limitation: shouldn't it fail?
Date: Tue, 04 Mar 2003 16:27:02 +0100

At least with libc-2.3.1, getcwd can fail, yet give no indication
of the problem.

If the current working directory is longer (including trailing NUL)
than PATH_MAX, then getcwd returns the prefix consisting of as many
file name components as *do* fit in PATH_MAX bytes.  And since the
first omitted component may have up to _POSIX_NAME_MAX (or pathconf
(".", _PC_NAME_MAX)) bytes, the length of the returned string may be
that much smaller than PATH_MAX.

Shouldn't getcwd simply fail in that case, and set
errno to ENAMETOOLONG?

Otherwise, any _robust_ code that uses getcwd must resort to doing a
pair of lstat calls and a dev/ino comparison to detect this failure,
but only when strlen of the result is larger than PATH_MAX - UB - 1
where UB is an upper bound on the length of the omitted component and
the slash preceding it.

Jim

Attachment: pgp28jugp0BUn.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]