Skip to content

Commit bbc1bd9

Browse files
authored
Null pointer protections (#889)
* Started to work on fixing issue #863 by making sure that we always test for a valid process object did some formatting * more null pointer protections
1 parent 0bddc32 commit bbc1bd9

18 files changed

Lines changed: 413 additions & 352 deletions

File tree

lib/libELF/include/libELF/elf_syminfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ enum {
120120

121121
template <class T>
122122
constexpr T ELF32_ST_VISIBILITY(T o) {
123-
return ((o)&0x03);
123+
return ((o) & 0x03);
124124
}
125125

126126
/* For ELF64 the definitions are the same. */

plugins/Analyzer/Analyzer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,13 @@ void Analyzer::bonusMain(RegionData *data) const {
368368

369369
Q_ASSERT(data);
370370

371-
const QString s = edb::v1::debugger_core->process()->executable();
372-
if (!s.isEmpty()) {
373-
if (const edb::address_t main = edb::v1::locate_main_function()) {
374-
if (data->region->contains(main)) {
375-
data->knownFunctions.insert(main);
371+
if (IProcess *process = edb::v1::debugger_core->process()) {
372+
const QString s = process->executable();
373+
if (!s.isEmpty()) {
374+
if (const edb::address_t main = edb::v1::locate_main_function()) {
375+
if (data->region->contains(main)) {
376+
data->knownFunctions.insert(main);
377+
}
376378
}
377379
}
378380
}

plugins/BinaryInfo/ELFXX.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ ELFXX<ElfHeader>::ELFXX(const std::shared_ptr<IRegion> &region)
109109
}
110110
} else if (header_.e_type == ET_DYN) {
111111

112-
const QString process_executable = edb::v1::debugger_core->process()->name();
113-
for (const std::shared_ptr<IRegion> &r : edb::v1::memory_regions().regions()) {
114-
if (r->accessible() && r->name() == region->name()) {
115-
lowest = std::min(lowest, r->start());
112+
if (IProcess *process = edb::v1::debugger_core->process()) {
113+
const QString process_executable = process->name();
114+
for (const std::shared_ptr<IRegion> &r : edb::v1::memory_regions().regions()) {
115+
if (r->accessible() && r->name() == region->name()) {
116+
lowest = std::min(lowest, r->start());
117+
}
116118
}
117119
}
118120
}

plugins/CheckVersion/CheckVersion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void CheckVersion::setProxy(const QUrl &url) {
101101
if (!proxy_str.isEmpty()) {
102102
const QUrl proxy_url = QUrl::fromUserInput(proxy_str);
103103
const int port = proxy_url.port(80);
104-
const auto qport = static_cast<quint16>(qBound(0, port, 65535));
104+
const auto qport = static_cast<quint16>(qBound(0, port, 65535));
105105

106106
proxy = QNetworkProxy(QNetworkProxy::HttpProxy, proxy_url.host(), qport, proxy_url.userName(), proxy_url.password());
107107
}

plugins/DebuggerCore/unix/openbsd/PlatformState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ void PlatformState::set_instruction_pointer(edb::address_t value) {
414414
#if defined(EDB_X86)
415415
regs_.r_eip = value;
416416
#elif defined(EDB_X86_64)
417-
regs_.r_rip = value;
417+
regs_.r_rip = value;
418418
#endif
419419
}
420420

plugins/DebuggerCore/unix/osx/DebuggerCore.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ void DebuggerCore::set_state(const State &state) {
398398
// const thread_state_flavor_t fpu_flavor = x86_FLOAT_STATE32;
399399
// const thread_state_flavor_t exception_flavor = x86_EXCEPTION_STATE32;
400400
#elif defined(EDB_X86_64)
401-
mach_msg_type_number_t state_count = x86_THREAD_STATE64_COUNT;
402-
const thread_state_flavor_t flavor = x86_THREAD_STATE64;
403-
const thread_state_flavor_t debug_flavor = x86_DEBUG_STATE64;
401+
mach_msg_type_number_t state_count = x86_THREAD_STATE64_COUNT;
402+
const thread_state_flavor_t flavor = x86_THREAD_STATE64;
403+
const thread_state_flavor_t debug_flavor = x86_DEBUG_STATE64;
404404
// const thread_state_flavor_t fpu_flavor = x86_FLOAT_STATE64;
405405
// const thread_state_flavor_t exception_flavor = x86_EXCEPTION_STATE64;
406406
#endif

plugins/DebuggerCore/unix/osx/PlatformState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ void PlatformState::set_instruction_pointer(edb::address_t value) {
468468
#if defined(EDB_X86)
469469
thread_state_.REG(eip) = value;
470470
#elif defined(EDB_X86_64)
471-
thread_state_.REG(rip) = value;
471+
thread_state_.REG(rip) = value;
472472
#endif
473473
}
474474

plugins/DebuggerCore/win32/PlatformRegion.cpp

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,44 +113,47 @@ size_t PlatformRegion::size() const {
113113
* @param execute
114114
*/
115115
void PlatformRegion::setPermissions(bool read, bool write, bool execute) {
116-
if (HANDLE ph = OpenProcess(PROCESS_VM_OPERATION, FALSE, edb::v1::debugger_core->process()->pid())) {
117-
DWORD prot = PAGE_NOACCESS;
118-
119-
switch ((static_cast<int>(read) << 2) | (static_cast<int>(write) << 1) | (static_cast<int>(execute) << 0)) {
120-
case 0x0:
121-
prot = PAGE_NOACCESS;
122-
break;
123-
case 0x1:
124-
prot = PAGE_EXECUTE;
125-
break;
126-
case 0x2:
127-
prot = PAGE_WRITECOPY;
128-
break;
129-
case 0x3:
130-
prot = PAGE_EXECUTE_WRITECOPY;
131-
break;
132-
case 0x4:
133-
prot = PAGE_READONLY;
134-
break;
135-
case 0x5:
136-
prot = PAGE_EXECUTE_READ;
137-
break;
138-
case 0x6:
139-
prot = PAGE_READWRITE;
140-
break;
141-
case 0x7:
142-
prot = PAGE_EXECUTE_READWRITE;
143-
break;
144-
}
145-
146-
prot |= permissions_ & ~KnownPermissions; // keep modifiers
147116

148-
DWORD prev_prot;
149-
if (VirtualProtectEx(ph, reinterpret_cast<LPVOID>(start().toUint()), size(), prot, &prev_prot)) {
150-
permissions_ = prot;
117+
if (IProcess *process = edb::v1::debugger_core->process()) {
118+
if (HANDLE ph = OpenProcess(PROCESS_VM_OPERATION, FALSE, process->pid())) {
119+
DWORD prot = PAGE_NOACCESS;
120+
121+
switch ((static_cast<int>(read) << 2) | (static_cast<int>(write) << 1) | (static_cast<int>(execute) << 0)) {
122+
case 0x0:
123+
prot = PAGE_NOACCESS;
124+
break;
125+
case 0x1:
126+
prot = PAGE_EXECUTE;
127+
break;
128+
case 0x2:
129+
prot = PAGE_WRITECOPY;
130+
break;
131+
case 0x3:
132+
prot = PAGE_EXECUTE_WRITECOPY;
133+
break;
134+
case 0x4:
135+
prot = PAGE_READONLY;
136+
break;
137+
case 0x5:
138+
prot = PAGE_EXECUTE_READ;
139+
break;
140+
case 0x6:
141+
prot = PAGE_READWRITE;
142+
break;
143+
case 0x7:
144+
prot = PAGE_EXECUTE_READWRITE;
145+
break;
146+
}
147+
148+
prot |= permissions_ & ~KnownPermissions; // keep modifiers
149+
150+
DWORD prev_prot;
151+
if (VirtualProtectEx(ph, reinterpret_cast<LPVOID>(start().toUint()), size(), prot, &prev_prot)) {
152+
permissions_ = prot;
153+
}
154+
155+
CloseHandle(ph);
151156
}
152-
153-
CloseHandle(ph);
154157
}
155158
}
156159

plugins/ODbgRegisterView/DialogEditGPR.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ private Q_SLOTS:
7777
void setupFocus();
7878

7979
private:
80-
std::array<QLabel *, ENTRY_COLS + ENTRY_ROWS> labels_ = {{nullptr}};
81-
std::array<GprEdit *, FULL_LENGTH_ROWS *ENTRY_COLS + CHAR_COLS> entries_ = {{nullptr}};
80+
std::array<QLabel *, ENTRY_COLS + ENTRY_ROWS> labels_ = {{nullptr}};
81+
std::array<GprEdit *, FULL_LENGTH_ROWS * ENTRY_COLS + CHAR_COLS> entries_ = {{nullptr}};
8282
std::uint64_t value_;
8383
std::size_t bitSize_ = 0;
8484
Register reg_;

plugins/ODbgRegisterView/Plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void Plugin::setupDocks() {
5454

5555
void Plugin::saveSettings() const {
5656
QSettings settings;
57-
const auto size = static_cast<int>(registerViews_.size());
57+
const auto size = static_cast<int>(registerViews_.size());
5858
const auto arrayKey = pluginName + "/" + views;
5959
settings.remove(arrayKey);
6060
settings.beginWriteArray(arrayKey, size);

0 commit comments

Comments
 (0)