Merge "Improve <sys/xattr.h> coverage." am: 9f46c9e291
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1623241 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ic15fccc85ccdf2f5c06061ad6ca78f1c09115028
This commit is contained in:
commit
59c5c294f9
3 changed files with 13 additions and 6 deletions
|
@ -37,7 +37,7 @@
|
|||
|
||||
extern "C" ssize_t __fgetxattr(int, const char*, void*, size_t);
|
||||
|
||||
ssize_t fgetxattr(int fd, const char *name, void *value, size_t size) {
|
||||
ssize_t fgetxattr(int fd, const char* name, void* value, size_t size) {
|
||||
int saved_errno = errno;
|
||||
ssize_t result = __fgetxattr(fd, name, value, size);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
extern "C" ssize_t __flistxattr(int, char*, size_t);
|
||||
|
||||
ssize_t flistxattr(int fd, char *list, size_t size) {
|
||||
ssize_t flistxattr(int fd, char* list, size_t size) {
|
||||
int saved_errno = errno;
|
||||
ssize_t result = __flistxattr(fd, list, size);
|
||||
if (result != -1 || errno != EBADF) {
|
||||
|
@ -45,7 +45,7 @@ ssize_t flistxattr(int fd, char *list, size_t size) {
|
|||
}
|
||||
|
||||
// fd could be an O_PATH file descriptor, and the kernel
|
||||
// may not directly support fgetxattr() on such a file descriptor.
|
||||
// may not directly support flistxattr() on such a file descriptor.
|
||||
// Use /proc/self/fd instead to emulate this support.
|
||||
int fd_flag = fcntl(fd, F_GETFL);
|
||||
if (fd_flag == -1 || (fd_flag & O_PATH) == 0) {
|
||||
|
|
|
@ -55,13 +55,13 @@ TEST(sys_xattr, fsetxattr_toosmallbuf) {
|
|||
ASSERT_EQ(ERANGE, errno);
|
||||
}
|
||||
|
||||
TEST(sys_xattr, fsetxattr_invalidfd) {
|
||||
TEST(sys_xattr, fsetxattr_invalid_fd) {
|
||||
char buf[10];
|
||||
errno = 0;
|
||||
ASSERT_EQ(-1, fsetxattr(65535, "user.foo", "0123", 5, 0));
|
||||
ASSERT_EQ(-1, fsetxattr(-1, "user.foo", "0123", 5, 0));
|
||||
ASSERT_EQ(EBADF, errno);
|
||||
errno = 0;
|
||||
ASSERT_EQ(-1, fgetxattr(65535, "user.foo", buf, sizeof(buf)));
|
||||
ASSERT_EQ(-1, fgetxattr(-1, "user.foo", buf, sizeof(buf)));
|
||||
ASSERT_EQ(EBADF, errno);
|
||||
}
|
||||
|
||||
|
@ -127,3 +127,10 @@ TEST(sys_xattr, flistattr_opath) {
|
|||
#endif
|
||||
close(fd);
|
||||
}
|
||||
|
||||
TEST(sys_xattr, flistattr_invalid_fd) {
|
||||
char buf[65536]; // 64kB is max possible xattr list size. See "man 7 xattr".
|
||||
errno = 0;
|
||||
ASSERT_EQ(-1, flistxattr(-1, buf, sizeof(buf)));
|
||||
ASSERT_EQ(EBADF, errno);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue