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

Tests malloc/realloc return values in MemoryDataStream->write #661

merged 3 commits into from
Apr 28, 2016


Copy link

@festlv festlv commented Mar 21, 2016

malloc/realloc function call return values were not checked and used as buffers which could lead to NULL pointer de-referencing crashes.

Additionally, TcpClient->send now fails when there was no free space in underlying memory stream.

Copy link

@festlv :
Good catch.
Update to memorydatastream is OK.
On TCPClient. :
In the current implementation the side effect is that when closing the connection it will be detected as "not completely send data" because of the asyncTotalLen += len; .
After your update this is not updated -> asyncTotalLen == asyncTotalSent -> closed with "all OK'

Maybe should close the connection when data cannot be stored. The principle of TCP connection is a guaranteed transmission of data. Now we leave part of the data out.

Copy link
Contributor Author

festlv commented Mar 22, 2016

I actually realized that MemoryDataStream update will leak memory if initial malloc succeeds but realloc fails- buf is NULL and won't be freed. Will update the PR later.

Regarding TcpClient- I see your point. However, my update does not break this guarantee- the data which has been accepted for sending is sent. If TcpClient fails to send data (send returns false), application layer knows it right away and can act accordingly. Otherwise, the current implementation will discard data and application will only learn about this later.

Copy link

Can you make a PR for SmingRTOS too ?

@hreintke hreintke merged commit 28e77e6 into SmingHub:develop Apr 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants