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

Merged
merged 3 commits into from Apr 28, 2016

Projects

None yet

2 participants

@festlv
Contributor
festlv commented Mar 21, 2016 edited

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.

@hreintke
Contributor

@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.

@festlv
Contributor
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.

@hreintke
Contributor

Can you make a PR for SmingRTOS too ?

@hreintke hreintke merged commit 28e77e6 into SmingHub:develop Apr 28, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@hreintke hreintke removed the PR_Progress label Apr 28, 2016
@HappyCodingRobot HappyCodingRobot added a commit to HappyCodingRobot/Sming that referenced this pull request May 1, 2016
@HappyCodingRobot HappyCodingRobot Squashed commit of the following:
commit f920333
Merge: c7194f3 d9b3af0
Author: alonewolfx2 <alonewolf07@gmail.com>
Date:   Sat Apr 30 13:33:53 2016 +0300

    Merge pull request #654 from harry-boe/device/ArduCAM

    - initial ArduCAM library and sample replaces #646

commit c7194f3
Merge: 28e77e6 fb9c5d7
Author: alonewolfx2 <alonewolf07@gmail.com>
Date:   Fri Apr 29 11:26:00 2016 +0300

    Merge pull request #719 from patrickjahns/patch1

    remove old temp file

commit fb9c5d7
Author: Patrick Jahns <github@patrickjahns.de>
Date:   Fri Apr 29 10:12:29 2016 +0200

    remove old temp file

commit 28e77e6
Merge: 19ead26 1966de6
Author: hreintke <hreintke@tauri.nl>
Date:   Thu Apr 28 22:52:12 2016 +0200

    Merge pull request #661 from festlv/bugfix_tcpclient

    Tests malloc/realloc return values in MemoryDataStream->write

commit 19ead26
Merge: f260cb0 23a8782
Author: hreintke <hreintke@tauri.nl>
Date:   Thu Apr 28 22:48:58 2016 +0200

    Merge pull request #684 from ril3y/patch-1

    fixed a bug in example.  th stuct was not used to print.

commit f260cb0
Merge: 444ffd6 c25a2b5
Author: hreintke <hreintke@tauri.nl>
Date:   Wed Apr 27 18:12:06 2016 +0200

    Merge pull request #714 from patrickjahns/fix/tcpconnection-timeout

    return TimeoutError when timeout occured

commit c25a2b5
Author: Patrick Jahns <github@patrickjahns.de>
Date:   Mon Apr 25 23:27:59 2016 +0200

    return TimeoutError when timeout occured

commit 23a8782
Author: Riley <rileyporter@gmail.com>
Date:   Mon Apr 4 22:51:28 2016 -0400

    fixed a bug in example.  th stuct was not used to print.

commit 1966de6
Author: Reinis Veips <reinis.veips@wot.lv>
Date:   Thu Mar 24 23:09:02 2016 +0200

    Fixes potential memory leak in DataSourceStream if realloc fails.

commit 1464a0d
Author: Reinis Veips <reinis.veips@wot.lv>
Date:   Mon Mar 21 23:59:27 2016 +0200

    Tests if MemoryDataStream->write was successful when sending.

commit 95159c0
Author: Reinis Veips <reinis.veips@wot.lv>
Date:   Mon Mar 21 23:59:03 2016 +0200

    Checks malloc/realloc return values when writing to stream.

commit d9b3af0
Author: Harry Böttcher <harald.boettcher@ti8m.ch>
Date:   Wed Mar 16 00:14:41 2016 +0100

    added WebUI to control camera

commit 76c32a1
Author: Harry Böttcher <hbottc@gmail.com>
Date:   Mon Mar 14 17:55:50 2016 +0100

    - initial ArduCAM library and sample

    	Branch rebuild to cleanup commit history
8a79820
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment