nathhB / nbnet

single header C(99) library to implement client-server network code for games
zlib License
441 stars 30 forks source link

Fix buffer overflow when handling large signalling descriptions #62

Closed alufers closed 3 months ago

alufers commented 3 months ago

This can happen when a computer has lots of network interfaces, for example when running docker.

This is the signalling JSON from my PC:

{"type":"answer", "sdp":"v=0\r\no=rtc 190772944 0 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=msid-semantic:WMS *\r\na=ice-options:ice2,trickle\r\na=fingerprint:sha-256 14:C6:74:62:AF:64:75:F9:07:30:5B:F5:13:06:BD:0A:2F:E1:69:A3:2E:83:43:9E:93:57:FF:51:0E:70:D7:CD\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\na=mid:0\r\na=sendrecv\r\na=sctp-port:5000\r\na=max-message-size:262144\r\na=setup:active\r\na=ice-ufrag:HRcS\r\na=ice-pwd:npVVI0DyEA2/KXM7q/u3r4\r\na=candidate:9 1 UDP 2130704383 fdbf:cd27:1133::9 60386 typ host\r\na=candidate:1 1 UDP 2122317823 X.X.X.X 60386 typ host\r\na=candidate:2 1 UDP 2122317567 X.X.X.X 60386 typ host\r\na=candidate:3 1 UDP 2122317311 172.18.0.1 60386 typ host\r\na=candidate:4 1 UDP 2122317055 172.23.0.1 60386 typ host\r\na=candidate:5 1 UDP 2122316799 172.19.0.1 60386 typ host\r\na=candidate:6 1 UDP 2122316543 172.20.0.1 60386 typ host\r\na=candidate:7 1 UDP 2122316287 172.25.0.1 60386 typ host\r\na=candidate:8 1 UDP 2122316031 172.26.0.1 60386 typ host\r\na=end-of-candidates\r\n"}

it did not fit in the 1024 byte buffer, so I changed it to a dynamically allocated one on the heap. This code runs only when establishing a connection, so some dynamic allocation is not that bad.

alufers commented 3 months ago

Addressed comments. Sorry for missing that, I was in a bit of a rush to finish a project for uni and didn't notice that :)

nathhB commented 3 months ago

@alufers thank you very much for your contribution