!595 fix warning

Merge pull request !595 from 张文迪/gid
This commit is contained in:
openharmony_ci 2023-08-14 13:20:55 +00:00 committed by Gitee
commit 3ec99f13e7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 20 additions and 3 deletions

View File

@ -277,8 +277,13 @@ static int ReadKeyFile(const char *path, char *buf, size_t len)
FSCRYPT_LOGE("target file size is not equal to buf len"); FSCRYPT_LOGE("target file size is not equal to buf len");
return -EFAULT; return -EFAULT;
} }
char *realPath = realpath(path, NULL);
if (realPath == NULL) {
FSCRYPT_LOGE("realpath failed");
return -EFAULT;
}
int fd = open(path, O_RDONLY); int fd = open(realPath, O_RDONLY);
if (fd < 0) { if (fd < 0) {
FSCRYPT_LOGE("key file read open failed"); FSCRYPT_LOGE("key file read open failed");
return -EFAULT; return -EFAULT;

View File

@ -64,7 +64,13 @@ long KeyCtrlUnlink(key_serial_t key, key_serial_t keyring)
static bool FsIoctl(const char *mnt, unsigned long cmd, void *arg) static bool FsIoctl(const char *mnt, unsigned long cmd, void *arg)
{ {
int fd = open(mnt, O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); char *realPath = realpath(mnt, NULL);
if (realPath == NULL) {
FSCRYPT_LOGE("realpath failed");
return false;
}
int fd = open(realPath, O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
if (fd < 0) { if (fd < 0) {
FSCRYPT_LOGE("open %s failed, errno:%d", mnt, errno); FSCRYPT_LOGE("open %s failed, errno:%d", mnt, errno);
return false; return false;
@ -119,7 +125,13 @@ bool KeyCtrlGetPolicy(const char *path, struct fscrypt_policy *policy)
static uint8_t CheckKernelFscrypt(const char *mnt) static uint8_t CheckKernelFscrypt(const char *mnt)
{ {
int fd = open(mnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC); char *realPath = realpath(mnt, NULL);
if (realPath == NULL) {
FSCRYPT_LOGE("realpath failed");
return -EFAULT;
}
int fd = open(realPath, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if (fd < 0) { if (fd < 0) {
FSCRYPT_LOGE("open policy file failed, errno: %d", errno); FSCRYPT_LOGE("open policy file failed, errno: %d", errno);
return FSCRYPT_INVALID; return FSCRYPT_INVALID;