From: Lukasz Bardeli Date: Mon, 24 Feb 2020 10:08:21 +0000 (+0100) Subject: [Filesystem] fix for preventing integer overflow during subtraction. X-Git-Tag: submit/tizen/20200225.093834~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11350f11fd0a96e91bcbfbad30d0003cf8bae127;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] fix for preventing integer overflow during subtraction. Filesystem TCT passrate 100% Deprecated TCT passrate 100% Change-Id: Ia2bf2bd10d79cf5bfba1bc4597ab7b1b5c634b02 Signed-off-by: Lukasz Bardeli --- diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 0e71a148..9855c502 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -336,8 +336,12 @@ static std::vector read_file(std::string path, long offset = 0, }; auto size = file_size(file); - if (offset < 0 || size <= (size_t)offset || - (0 != offset && 0 != std::fseek(file, offset, SEEK_SET))) { + if (offset < 0 || size < (size_t)offset) { + std::string err_msg = std::string("offset is smaller than zero or greater than size."); + throw std::system_error{EINVAL, std::generic_category(), err_msg}; + } + + if (0 != offset && 0 != std::fseek(file, offset, SEEK_SET)) { std::string err_msg = std::string("Cannot perform seek. ") + GetErrorString(errno); throw std::system_error{errno, std::generic_category(), err_msg}; }