asyn icon indicating copy to clipboard operation
asyn copied to clipboard

Probable bug in 'drvAsynIPServerPort', function 'readIt()'

Open jafonso opened this issue 6 years ago • 2 comments

Hello,

I am using 'drvAsynIPServerPort' to read binary data from a UDP/IP packet into a structure, and I noticed that the function 'readIt()' is not reading the last byte.

This may be intentional, but if not, the issue seems to be with lines 195-197 from drvAsynIPServerPort.c:

for (x = 0; x < (int)maxchars - 1; x++) { data[x] = tty->UDPbuffer[x + tty->UDPbufferPos]; }

With this implementation, if I ask it to fill a structure of exactly N bytes, it will only fill N-1. Considering this, I propose modifying 'maxchar-1' to 'maxchar'.

I don't think it will mess up with string data, because the termination character will always be added later (lines 231-232), if there is enough space.

if (thisRead < (int) maxchars) data[thisRead] = 0;

In addition, I think the remaining size of tty->UDPbuffer[] should be checked before the reading of maxchar characters, otherwise it seems to me that there is nothing stopping a client from reading beyond the end of the array.

jafonso avatar Mar 29 '19 16:03 jafonso

In addition, I think the remaining size of tty->UDPbuffer[] should be checked before the reading of maxchar characters, otherwise it seems to me that there is nothing stopping a client from reading beyond the end of the array.

Can you add the code to do this, test it, and create a pull request? Thanks.

MarkRivers avatar Oct 18 '19 23:10 MarkRivers