From cc97c0e5253f957fc6eb9dbbf254e616b5b32b8d Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 18 Jan 2024 10:11:06 +0000 Subject: [PATCH] fix: Segfault when launching ImHex with file arguments (#1501) d511080814dc78ad39a63f2071003c07ee37673c introduced a regression where running imhex with arguments (i.e. `imhex blob1.bin blob2.bin`) will segfault due to a null pointer dereference. ### Implementation description This patch updates `getSubCommands` to follow the same control flow as `getFeatures`, where if the function returns a null pointer, it will return gracefully rather than crash. --- lib/libimhex/source/api/plugin_manager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/libimhex/source/api/plugin_manager.cpp b/lib/libimhex/source/api/plugin_manager.cpp index f9ed8636b..d2b4e07cc 100644 --- a/lib/libimhex/source/api/plugin_manager.cpp +++ b/lib/libimhex/source/api/plugin_manager.cpp @@ -186,6 +186,8 @@ namespace hex { std::span Plugin::getSubCommands() const { if (m_functions.getSubCommandsFunction != nullptr) { const auto result = m_functions.getSubCommandsFunction(); + if (result == nullptr) + return { }; return *static_cast*>(result); } else {