tech-userlevel archive

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

Re: MAXPATHLEN vs PATH_MAX



Le Sat, May 27, 2023 at 08:50:21PM +0000, David Holland a écrit :
> On Sat, May 27, 2023 at 09:10:34AM +0200, tlaronde%polynum.com@localhost wrote:
>  > Shouldn't be MAXPATHLEN be defined as PATH_MAX - 1?
> 
> No. They're the same. The existence of some old code where somebody
> didn't read the definition carefully (or that predates a clear
> definition) doesn't change that. Not sure why you think it should...

The comment in sys/param.h:

/*
 * MAXPATHLEN defines the longest permissible path length after expanding
 * symbolic links. It is used to allocate a temporary buffer from the buffer
 * pool in which to do the name expansion, hence should be a power of two,
 * and must be less than or equal to MAXBSIZE.  MAXSYMLINKS defines the
 * maximum number of symbolic links that may be expanded in a path name.
 * It should be set high enough to allow all legitimate uses, but halt
 * infinite loops reasonably quickly.
 *
 * MAXSYMLINKS should be >= _POSIX_SYMLOOP_MAX (see <limits.h>)
 */

It uses once more "length" so that, reading it, a user (at least me)
doesn't know if it is a string length or a buffer size so if the buffer
is (MAXPATHLEN+1) or MAXPATHLEN. Onc could argue that if one reads
"carefully", since a power of two is wanted, one can not add 1 since it
will not be a power of two anymore... But this would be arguing.

Shouldn't MAXPATHLEN be marked as deprecated precisely because of the
unfortunate ambiguity of its name, PATH_MAX being prefered in it's stead, and the
comment modified to clearly state it is a size and not a length?

BTW I have realized that modifying the definition to match the "description"
will impose to review all the code (old and added) to track an of by one
problem, so it would introduce a can of worms.

IMHO, at least the comment should be amended to state things more clearly and to
not use "length".
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index