Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV when subscribing to multiple topics #524

Open
elekTom opened this issue Nov 21, 2024 · 0 comments
Open

SIGSEGV when subscribing to multiple topics #524

elekTom opened this issue Nov 21, 2024 · 0 comments

Comments

@elekTom
Copy link

elekTom commented Nov 21, 2024

I encountered a nullptr deref when subscribing to multiple topics with custom options.
See example below:

std::vector<std::string> topicList;
std::vector<int> qosList;
std::vector<mqtt::subscribe_options> subOptsList;
// -----
// fill lists with data
// -----
const auto resp = client->subscribe(topicList, qosList, subOptsList);  // <-- causes SIGSEGV 

More specifically, the nullptr deref happens in MQTTAsync_subscribeMany() because response->subscribeOptionsList is NULL here.

I think this is caused by response_options copy constructor not copying subOpts_.
This means that when response_options_builder::finalize() is called, a response_options instance with subOpts_.data()==nullptr is returned.

My current fix for this looks like this. Although I don't know if there is more to this than that:

diff --git a/src/response_options.cpp b/src/response_options.cpp
index 62166f5..100a373 100644
--- a/src/response_options.cpp
+++ b/src/response_options.cpp
@@ -36,7 +36,7 @@ response_options::response_options(const token_ptr& tok,
 }
 
 response_options::response_options(const response_options& other)
-	: opts_(other.opts_), tok_(other.tok_), props_(other.props_)
+	: opts_(other.opts_), tok_(other.tok_), props_(other.props_), subOpts_(other.subOpts_)
 {
 	update_c_struct();
 }

System info

OS: win11
Compiler: mingw64 12.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant