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

Use of uninitialized variable when handling connack packet #566

Open
fmeef opened this issue Jan 3, 2020 · 2 comments
Open

Use of uninitialized variable when handling connack packet #566

fmeef opened this issue Jan 3, 2020 · 2 comments

Comments

@fmeef
Copy link

fmeef commented Jan 3, 2020

When compiled with -fsanitize=undefined on gcc 9.2.0, gcc's undefined behavior sanitizer warns with the message

mqtt_cpp/include/mqtt/endpoint.hpp:6002:12: runtime error: load of value 252, which is not a valid value for type 'bool' .

This seems to be caused by the session_present member of connack_info not being initialized. As a possible workaround, adding info.session_present = true; at line 6025 of endpoint.cpp fixes the problem, at least from the sanitizer's point of view.

@redboltz
Copy link
Owner

redboltz commented Jan 9, 2020

Thank you for reporting the issue.

I guess that you mean

bool session_present;

The member session_present is assigned at

info.session_present = is_session_present(buf[0]);

But it is one of case clause. Even if connack_phase::header becomes earlier than refers it, sanitizer might warn about that. I understand it.

Just my preference, I will insert info.serssion_present = false; at

The line number could update when master is updated, so I recommend that use some commit just as I do.

@jonesmz
Copy link
Contributor

jonesmz commented Jan 9, 2020

My guess is that the problem is happening when the struct is copied as a parameter into the function call.

So setting info.serssion_present = false; right after constructing the info object should fix the problem. I've confirmed as much on my end, but maybe you have a better idea,

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

3 participants