MAXPATHLEN / PATH_MAX includes space for the terminating NUL, and namei verifies the presence of the NUL. Thus there is no need to increase the buffer size here. Still write the NUL in case of misuse of the sysctl.
|358 ↗||(On Diff #62830)|
presumably we could use sysctl_handle_string here instead, something like
buf = malloc(PATH_MAX, M_TEMP, M_WAITOK); buf = '\0'; error = sysctl_handle_string(oidp, arg1, arg2, req); if (error != 0) goto out; ndflags = ...
@kib pointed out on IRC that the original PATH_MAX + 1 is incorrect but arguably innocent and I agree, but think it is worth the change to avoid confusing folks (who find that code) into wondering if PATH_MAX includes space for the NUL or not - that's what prompted me to look at this in the first place.
|354 ↗||(On Diff #62836)|
IMO it's a separate issue of similar confusion.
First issue is whether a buffer of PATH_MAX bytes is sufficient to hold a longest-possible pathname; it is.
Second is whether strings passed to sysctl include the NUL in newlen, inspection shows they don't, so this could be if (req->newlen >= PATH_MAX)