-
-
Notifications
You must be signed in to change notification settings - Fork 1k
notification: Initialise message #1694
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
notification: Initialise message #1694
Conversation
Prevents reading uninitialised memory if notification gets cut off due to being more than 100 chars. The last character is assumed to be \0, but it is actually uninitialised.
|
Build size and comparison to main:
|
|
Can you show where and how this issue occurs, so we can verify it? |
|
I don't think that this has ever caused an issue, but if a message gets sent to the watch with more than 100 chars, the first 100 are copied, where the last of those won't be a null-terminator. To solve that, the message array holds 101 chars, so that the last one will be a null-terminator. Except because it's not initialised, it is technically an indeterminate value unless explicitly written to. This is just a memory safety change, and both |
|
It would still be assuming that the struct is being used in the correct way. Someone could still fill the entire array. Maybe the public notification struct should use an std::string, which when pushing the notification would then be converted to a private format which uses a char array in a safe way. |
minacode
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. It's simple, clean and more sane. Any more complex refactoring can be done a new PR, if needed.
Haven't tested it, but the code change is so minimal that I would be very surprised if this breaks something.
|
I agree. Minimal code change resulting in a sane memory default. @FintasticMan could you update this PR to see if it is still applicable or if we changed it already in a similar way since then? |
|
I think this PR is still applicable. The implementation of The conflict that appears when rebasing should be quite easy to fix, it seems to be caused by the order of the fields that changed since this change was originally made. |
Prevents reading uninitialised memory if notification gets cut off due to being more than 100 chars. The last character is assumed to be
\0, but it is actually uninitialised.