From: Rafal Walczyna Date: Sun, 27 May 2018 07:13:01 +0000 (+0200) Subject: [filesystem] Fixing SVACE issues, type PROC_USE.VULNERABLE X-Git-Tag: submit/tizen/20180527.080835^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c1337f5c9922f2ecd5937f30622b26b98b2faeff;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [filesystem] Fixing SVACE issues, type PROC_USE.VULNERABLE WGIDs: 346838, 346836, 346837, 346838, 346839, 346840 [verification] TCT auto tests 100% passrate on TM1 20180524.2 Change-Id: I37557679b68be53f479a99fed73b58ca5291ab21 Signed-off-by: Rafal Walczyna --- diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 63abe820..733d75d3 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -35,6 +35,9 @@ namespace extension { namespace filesystem { namespace { + +using common::tools::GetErrorString; + // The privileges that required in Filesystem API const std::string kPrivilegeFilesystemRead = "http://tizen.org/privilege/filesystem.read"; const std::string kPrivilegeFilesystemWrite = "http://tizen.org/privilege/filesystem.write"; @@ -87,8 +90,7 @@ FileHandle::~FileHandle() { ScopeLogger(); if (file_handle && std::fclose(file_handle)) { - int errsv = errno; - LoggerE("close file failed, error message: %s", strerror(errsv)); + LoggerE("close file failed, error message: %s", GetErrorString(errno).c_str()); } } @@ -366,7 +368,7 @@ static std::vector read_file(std::string path, long offset = 0, FILE* file = std::fopen(path.c_str(), "r"); if (!file) { - std::string err_msg = std::string("Cannot open file to read. ") + strerror(errno); + std::string err_msg = std::string("Cannot open file to read. ") + GetErrorString(errno); throw std::system_error{errno, std::generic_category(), err_msg}; } @@ -378,7 +380,7 @@ static std::vector read_file(std::string path, long offset = 0, }; if (0 != offset && 0 != std::fseek(file, offset, SEEK_SET)) { - std::string err_msg = std::string("Cannot perform seek. ") + strerror(errno); + std::string err_msg = std::string("Cannot perform seek. ") + GetErrorString(errno); throw std::system_error{errno, std::generic_category(), err_msg}; } @@ -408,7 +410,7 @@ static std::vector read_file(FILE* file, std::size_t length /*= NP data_p += std::fread(data_p, 1, end_p - data_p, file); if (std::ferror(file)) { - std::string err_msg = std::string("Error during file read. ") + strerror(errno); + std::string err_msg = std::string("Error during file read. ") + GetErrorString(errno); throw std::runtime_error(err_msg); } @@ -432,13 +434,13 @@ void write_file(const std::uint8_t* data, std::size_t len, FILE* file) { data_p += fwrite(data_p, 1, end_p - data_p, file); if (std::ferror(file)) { - std::string err_msg = std::string("Error during file write. ") + strerror(errno); + std::string err_msg = std::string("Error during file write. ") + GetErrorString(errno); throw std::runtime_error(err_msg); } } if (std::fflush(file)) { - std::string err_msg = std::string("Error during file write. ") + strerror(errno); + std::string err_msg = std::string("Error during file write. ") + GetErrorString(errno); throw std::runtime_error(err_msg); } } @@ -453,7 +455,7 @@ void write_file(const std::uint8_t* data, std::size_t len, std::string path, lon FILE* file = std::fopen(path.c_str(), mode); if (!file) { - std::string err_msg = std::string("Cannot open file to write. ") + strerror(errno); + std::string err_msg = std::string("Cannot open file to write. ") + GetErrorString(errno); throw std::runtime_error(err_msg); } @@ -465,7 +467,7 @@ void write_file(const std::uint8_t* data, std::size_t len, std::string path, lon }; if (offset != 0 && std::fseek(file, offset, SEEK_SET) != 0) { - std::string err_msg = std::string("Cannot perform seek. ") + strerror(errno); + std::string err_msg = std::string("Cannot perform seek. ") + GetErrorString(errno); throw std::system_error{errno, std::generic_category(), err_msg}; } @@ -1848,10 +1850,9 @@ void FilesystemInstance::FileHandleSeek(const picojson::value& args, picojson::o long ret = fseek(handle->file_handle, offset, whence); if (0 != ret) { LoggerE("fseek returned failed"); - int errsv = errno; std::string error_message = std::string("seek failed, fileHandle may be corrupted, error message: ") + - strerror(errsv); + GetErrorString(errno); LogAndReportError(IOException(error_message.c_str()), out); return; } @@ -1859,10 +1860,9 @@ void FilesystemInstance::FileHandleSeek(const picojson::value& args, picojson::o ret = ftell(handle->file_handle); if (-1L == ret) { LoggerE("ftell returned failed"); - int errsv = errno; std::string error_message = std::string("seek failed, fileHandle may be corrupted, error message: ") + - strerror(errsv); + GetErrorString(errno); LogAndReportError(IOException(error_message.c_str()), out); return; } @@ -2187,8 +2187,8 @@ void FilesystemInstance::FileHandleFlush(const picojson::value& args, picojson:: try { int ret = fflush(handle->file_handle); if (ret) { - int errsv = errno; - std::string error_message = std::string("flush failed, error message: ") + strerror(errsv); + std::string error_message = + std::string("flush failed, error message: ") + GetErrorString(errno); LogAndReportError(IOException(error_message.c_str()), out); return; } @@ -2236,8 +2236,8 @@ void FilesystemInstance::FileHandleSync(const picojson::value& args, picojson::o try { int ret = fsync(fileno(handle->file_handle)); if (ret) { - int errsv = errno; - std::string error_message = std::string("sync failed, error message: ") + strerror(errsv); + std::string error_message = + std::string("sync failed, error message: ") + GetErrorString(errno); LogAndReportError(IOException(error_message.c_str()), out); return; } @@ -2290,8 +2290,8 @@ void FilesystemInstance::FileHandleClose(const picojson::value& args, picojson:: int ret = fclose(handle->file_handle); handle->file_handle = nullptr; if (ret) { - int errsv = errno; - std::string error_message = std::string("close failed, error message: ") + strerror(errsv); + std::string error_message = + std::string("close failed, error message: ") + GetErrorString(errno); LogAndReportError(IOException(error_message.c_str()), out); return; }