Skip to content

Commit

Permalink
Fix null ptr dereference in MiscExtension and AudiStore (#2387)
Browse files Browse the repository at this point in the history
* Fix null ptr dereference in MiscExtension

* Fix null ptr dereference in AudiStore
  • Loading branch information
Harrm authored Mar 1, 2025
1 parent f258af6 commit 13a5631
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/authority_discovery/query/audi_store_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
namespace kagome::authority_discovery {

AudiStoreImpl::AudiStoreImpl(std::shared_ptr<storage::SpacedStorage> storage)
: space_{storage->getSpace(storage::Space::kAudiPeers)} {
: space_{storage->getSpace(storage::Space::kAudiPeers)},
log_{log::createLogger("AudiStore", "authority_discovery")} {
BOOST_ASSERT(space_ != nullptr);
}

Expand Down
2 changes: 2 additions & 0 deletions core/host_api/impl/misc_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ namespace kagome::host_api {
std::shared_ptr<const runtime::CoreApiFactory> core_factory)
: hasher_{std::move(hasher)},
memory_provider_{std::move(memory_provider)},
storage_provider_{std::move(storage_provider)},
core_factory_{std::move(core_factory)},
logger_{log::createLogger("MiscExtension", "misc_extension")} {
BOOST_ASSERT(hasher_);
BOOST_ASSERT(memory_provider_);
BOOST_ASSERT(storage_provider_);
}

runtime::WasmSpan MiscExtension::ext_misc_runtime_version_version_1(
Expand Down
6 changes: 5 additions & 1 deletion test/core/host_api/misc_extension_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "mock/core/runtime/core_api_factory_mock.hpp"
#include "mock/core/runtime/core_mock.hpp"
#include "mock/core/runtime/memory_provider_mock.hpp"
#include "mock/core/runtime/trie_storage_provider_mock.hpp"
#include "scale/scale.hpp"
#include "testutil/literals.hpp"
#include "testutil/prepare_loggers.hpp"
Expand All @@ -23,6 +24,7 @@ using kagome::host_api::MiscExtension;
using kagome::runtime::CoreApiFactoryMock;
using kagome::runtime::MemoryProviderMock;
using kagome::runtime::TestMemory;
using kagome::runtime::TrieStorageProviderMock;
using scale::encode;
using testing::_;
using testing::Invoke;
Expand Down Expand Up @@ -58,11 +60,13 @@ TEST_F(MiscExtensionTest, CoreVersion) {
return core;
}));

auto storage_provider = std::make_shared<TrieStorageProviderMock>();

kagome::host_api::MiscExtension m{
42,
std::make_shared<HasherMock>(),
memory_provider,
nullptr,
storage_provider,
core_factory,
};
ASSERT_EQ(memory[m.ext_misc_runtime_version_version_1(memory["test"_v])],
Expand Down

0 comments on commit 13a5631

Please sign in to comment.