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

esp8266 crashes when using payload in PROGMEM (v2.8) #747

Open
absalom-muc opened this issue Jun 14, 2020 · 1 comment · May be fixed by #1020
Open

esp8266 crashes when using payload in PROGMEM (v2.8) #747

absalom-muc opened this issue Jun 14, 2020 · 1 comment · May be fixed by #1020

Comments

@absalom-muc
Copy link

SInce the latest update (v2.8)
publish_P(const char* topic, const char* payload, boolean retained)
crashes when using it with payload located in PROGMEM.

Example: Using of
client.publish_P("outTopic_P", PSTR("test"), true);
was possible in v2.7, but no longer in v2.8. (tested with mqtt_esp8266)

Seems that the problem is in line 475
return publish_P(topic, (const uint8_t*)payload, payload ? strnlen(payload, this->bufferSize) : 0, retained);
Maybe better use strnlen_P.

Thank you.

@Erriez
Copy link

Erriez commented Oct 1, 2020

@absalom-muc Thanks for your post. I encountered the same problem and your suggested fix works for me.

I found another pull request to fix this here: https://github.com/knolleary/pubsubclient/pull/745/commits, but the build failed caused by an incorrect include of #include <avr/pgmspace.h> for ESP8266. I've added a comment to fix that, otherwise I can create a new pull request on master.

@knolleary what do you prefer to proceed?

muggenhor added a commit to muggenhor/pubsubclient that referenced this issue Jul 29, 2023
strnlen_P is needed to avoid the wrong method of reading to cause bad
things to happen (CPU exceptions on ESP8266).

Fixes: knolleary#747
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

Successfully merging a pull request may close this issue.

2 participants