base: parse_plist_config CFReadStreamCreateWithFile fail errors

If parse_plist_config() is called with a non-absolute path which
is defined as a path whose first character is not '/', then
CFReadStreamCreateWithFile() must determine the current working
directory in order to return a CFURLRef to an absolute path.
If getcwd() fails, then CFReadStreamCreateWithFile() returns
NULL.

Instead of unconditionally returning ENOMEM when NULL is returned,
check if the path is non-absolute and call getcwd().  If getcwd()
fails, return errno.  Otherwise, return ENOMEM.  This permits
ENOENT (a component of the pathname no longer exists) or EACCES
(read or search permission was denied for a component of the
pathname) to be returned as the reason.

ENOMEM is a fatal error when constructing the configuration for
krb5_init_context() whereas ENOENT and EACCES are not fatal.

Without this patch on macOS, if the cwd is in /afs and the user's
tokens have expired, then krb5_init_context() fails with ENOMEM (12).

  user@MacBookAir user % ~/src/heimdal/kuser/heimtools klist
  shell-init: error retrieving current directory: \
    getcwd: cannot access parent directories: Permission denied
  chdir: error retrieving current directory: \
    getcwd: cannot access parent directories: Permission denied
  heimtools: krb5_init_context failed: 12

With this change krb5_init_context() succeeds.
This commit is contained in:
Jeffrey Altman
2025-04-16 09:50:16 -04:00
parent caf18a8ef4
commit fd85f7ccb6

View File

@@ -312,6 +312,11 @@ parse_plist_config(heim_context context, const char *path, heim_config_section *
CFRelease(url);
if (s == NULL) {
heim_clear_error_message(context);
if (path[0] != '/') {
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) == NULL)
return errno;
}
return ENOMEM;
}