libselinux: set errno to EBADF on O_PATH emulation ENOENT failure
When the O_PATH emulation fails due to getxattr(2)/setxattr(2) failing
with ENOENT, e.g. because no procfs being available, override the errno
value to EBADF. This avoids confusion to the caller as it would suggest
the target of the operation does not exist, which is not the case:
setfiles: Could not set context for /: No such file or directory
Fixes: a782abf2
("libselinux: emulate O_PATH support in fgetfilecon/fsetfilecon")
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
parent
ebb4a170c0
commit
ba9820a002
|
@ -26,7 +26,10 @@ static ssize_t fgetxattr_wrapper(int fd, const char *name, void *value, size_t s
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "/proc/self/fd/%d", fd);
|
snprintf(buf, sizeof(buf), "/proc/self/fd/%d", fd);
|
||||||
errno = saved_errno;
|
errno = saved_errno;
|
||||||
return getxattr(buf, name, value, size);
|
ret = getxattr(buf, name, value, size);
|
||||||
|
if (ret < 0 && errno == ENOENT)
|
||||||
|
errno = EBADF;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fgetfilecon_raw(int fd, char ** context)
|
int fgetfilecon_raw(int fd, char ** context)
|
||||||
|
|
|
@ -25,7 +25,10 @@ static int fsetxattr_wrapper(int fd, const char* name, const void* value, size_t
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "/proc/self/fd/%d", fd);
|
snprintf(buf, sizeof(buf), "/proc/self/fd/%d", fd);
|
||||||
errno = saved_errno;
|
errno = saved_errno;
|
||||||
return setxattr(buf, name, value, size, flags);
|
rc = setxattr(buf, name, value, size, flags);
|
||||||
|
if (rc < 0 && errno == ENOENT)
|
||||||
|
errno = EBADF;
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsetfilecon_raw(int fd, const char * context)
|
int fsetfilecon_raw(int fd, const char * context)
|
||||||
|
|
Loading…
Reference in New Issue