Indeed, the test
strlen(home) > MAXPATHLEN - 8
is not sufficient due to the terminating null character
(if home has length MAXPATHLEN - 8, then MAXPATHLEN + 1
characters are written, which is larger than the buffer
size MAXPATHLEN).
See also:
b4e5968f0b