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

mqtt.cpp createFullTopicStr() (closed issue #6) #7

Open
WSchimi opened this issue Nov 27, 2021 · 0 comments
Open

mqtt.cpp createFullTopicStr() (closed issue #6) #7

WSchimi opened this issue Nov 27, 2021 · 0 comments

Comments

@WSchimi
Copy link

WSchimi commented Nov 27, 2021

Hi Pina,
sorry, i don't know how to reopen a closed issue (#6).

The ERROR IS NOT FIXED!

The code "(fullTopicStr topicLen 1) = '\0' writes 1 Byte behind the allocated memory!
Allocation code: "char* fullTopicStr = (char*) calloc(topicLen 1, sizeof(char));"
The management data of the pool or other important data may already be stored there.

Example: topicLen = 20:
-> 21 Bytes are allocated (from Byte *(fullTopicStr 0) till *(fullTopicStr 20) or *(fullTopicStr topicLen))
-> "(fullTopicStr topicLen 1) = '\0' writes at Byte 21 behind memory at pointer *fullTopicStr
-> my proposal for line 78: fullTopicStr[topicLen] = '\0'; or *(fullTopicStr topicLen) = '\0';

Best regards Walter

PS: calloc() clears all bits in the allocated memory. The ending '\0' does not have to be written ;) ... behind the allocated memory

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