diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 8f81a35c1f71c9f0043929bffabb7f939bf14066..c7cba5d56e957694769c0defc2823a907ef17c94 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -123,7 +123,12 @@ static UniqueFd GetFileHandleForSpecialCloneCloud(const string &fileName) throw BError(BError::Codes::EXT_INVAL_ARG, str); } } - return UniqueFd(open(fileName.data(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); + UniqueFd fd(open(fileName.data(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); + if (fd < 0) { + HILOGE("Open file failed, file name is %{private}s, err = %{public}d", fileName.data(), errno); + return UniqueFd(-1); + } + return fd; } UniqueFd BackupExtExtension::GetFileHandle(const string &fileName)