diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-20 04:12:31 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-20 04:12:31 +0300 |
commit | 9e68f4ed53ac6972474e2d0e4b00574cd374cd82 (patch) | |
tree | dbc3294ef862d35f985f78b83804a29fe165ccce /include/pdb | |
parent | code style (diff) | |
download | winapi-debug-9e68f4ed53ac6972474e2d0e4b00574cd374cd82.tar.gz winapi-debug-9e68f4ed53ac6972474e2d0e4b00574cd374cd82.zip |
code style
Diffstat (limited to '')
-rw-r--r-- | include/pdb/dbghelp.hpp | 4 | ||||
-rw-r--r-- | include/pdb/symbol.hpp | 21 |
2 files changed, 14 insertions, 11 deletions
diff --git a/include/pdb/dbghelp.hpp b/include/pdb/dbghelp.hpp index 7b018bc..d6b6899 100644 --- a/include/pdb/dbghelp.hpp +++ b/include/pdb/dbghelp.hpp @@ -22,6 +22,8 @@ namespace pdb DbgHelp(); ~DbgHelp(); + void close(); + ModuleInfo load_pdb(const std::string& path) const; typedef std::function<void (const SymbolInfo&)> OnSymbol; @@ -30,8 +32,6 @@ namespace pdb SymbolInfo resolve_symbol(Address) const; SymbolInfo resolve_symbol(const std::string&) const; - void close(); - private: ModuleInfo get_module_info(Address offline_base) const; 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: |