-
-
Notifications
You must be signed in to change notification settings - Fork 7k
do not trust received msg length to read forever #2781
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
Conversation
Bridge: discard message if length is bigger than buffer size
The
Now to get back to the issue: if an unlucky error happens (and I see that a timeout was already implemented in the loop: for (uint16_t i = 0; i < l; i++) {
int c = timedRead(5); <------- Read with a timeout of 5 ms
if (c < 0)
continue;
// Cut received data if rxbuffer is too small
if (i < rxlen)
rxbuff[i] = c;
crcUpdate(c);
} I guees that the main issue with this code is the use of |
@cmaglie If I understand you correctly, then the loop will break only if not receiving bytes (negative timedRead)? |
Exactly. To say in other words:
what is missing is the exit condition in case those
|
And if not reading them, the bytes will hang somewhere until they are read? So in other words, they will be read upon next |
Yes, if you do not read bytes from serial you will get them in the next round of BTW if the time-out happens it means that there are no bytes waiting in the queue, so the next transfer will probably be in sync. |
Sounds reasonable to break at |
A "solution" might be adding a |
Well, both the solutions have their side effects:
|
Bridge.put() was broken by arduino#2781 because it used transfer() 2-parameters overloaded version, which imply that rxlen == 0. Every bridge command (python side) has been checked and now SHOULD strictly follow this rule and never ignore silently the received data
Bridge.put() was broken by arduino#2781 because it used transfer() 2-parameters overloaded version, which imply that rxlen == 0. But the Linux Bridge responded, so the check (i >= rxlen) was true and the function timed out after retrying 50 times. Every bridge command (python side) has been checked and now SHOULD strictly follow this rule and never ignore silently the received data
The bridge will read up to 2^8 bytes of data, no matter what
rxlen
is fed toBridgeClass::transfer
. This will hang the bridge upon erroneous communication (as when Yun boots #2351). This PR fixes this. It breaks out of the read loop (when trying to further read and discard bytes) beyond what the read buffer can hold.Might also want to check out #2353, which also adds a check for the bridge, so that one can restart the bridge from the arduino side.