aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/pdb/symbol.hpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-05-20 04:12:31 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-05-20 04:12:31 +0300
commit9e68f4ed53ac6972474e2d0e4b00574cd374cd82 (patch)
treedbc3294ef862d35f985f78b83804a29fe165ccce /include/pdb/symbol.hpp
parentcode style (diff)
downloadwinapi-debug-9e68f4ed53ac6972474e2d0e4b00574cd374cd82.tar.gz
winapi-debug-9e68f4ed53ac6972474e2d0e4b00574cd374cd82.zip
code style
Diffstat (limited to 'include/pdb/symbol.hpp')
-rw-r--r--include/pdb/symbol.hpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/include/pdb/symbol.hpp b/include/pdb/symbol.hpp
index 12061bd..fc200c7 100644
--- a/include/pdb/symbol.hpp
+++ b/include/pdb/symbol.hpp
@@ -37,8 +37,11 @@ namespace pdb
: SymbolInfo{}
{
if (raw.SizeOfStruct != sizeof(raw))
- throw std::runtime_error{"unexpected symbol structure size"};
- std::memcpy(buffer, &raw, calc_size(raw));
+ throw std::runtime_error{"invalid SYMBOL_INFO.SizeOfStruct"};
+ const auto raw_size = calc_size(raw);
+ if (raw_size > sizeof(buffer))
+ throw std::runtime_error{"SYMBOL_INFO is too large"};
+ std::memcpy(buffer, &raw, raw_size);
}
explicit operator Raw&() { return raw; }
@@ -73,22 +76,22 @@ namespace pdb
bool is_function() const { return get_type() == Type::Function; }
private:
+ static constexpr std::size_t max_buffer_size = sizeof(Raw) + MAX_SYM_NAME - 1;
+
static std::size_t calc_size(const Raw& raw)
{
+ using namespace msl::utilities;
try
{
- msl::utilities::SafeInt<std::size_t> size{raw.SizeOfStruct};
- size += raw.NameLen;
- size -= 1;
- return size;
+ return SafeInt<std::size_t>{raw.SizeOfStruct} + raw.NameLen - 1;
}
- catch (const msl::utilities::SafeIntException&)
+ catch (const SafeIntException&)
{
- throw std::runtime_error{"symbol name is too long"};
+ throw std::runtime_error{"invalid SYMBOL_INFO size"};
}
}
- unsigned char buffer[sizeof(Raw) + MAX_SYM_NAME - 1] = {0};
+ unsigned char buffer[max_buffer_size] = {0};
Address displacement = 0;
protected: