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

Bug in rsi_ftp_file_write_content() causing stack corruption and deadlock #12

Open
adam-durridge opened this issue Jan 21, 2024 · 0 comments

Comments

@adam-durridge
Copy link

adam-durridge commented Jan 21, 2024

Sending data to an FTP server using multiple calls to rsi_ftp_file_write_content() can cause a serious bug to occur.

It can result in stack corruption (how I found it) and also gets the driver task in an incorrect state causing other Wi-Fi issues like lock ups until timeout.

It is due to how this SAPI call does not generate a response (RX Event) until the last chunk is sent. This

#ifndef RSI_UART_INTERFACE
if (!end_of_file) {
rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_ASYNCHRONOUS;
}
#endif

sets that expected response.

The problem is that on the last chunk, even though this block does not execute due to end_of_file being set, rsi_driver_cb->wlan_cb->expected_response is still equal to RSI_WLAN_RSP_ASYNCHRONOUS from the previous call.

This causes a wait for semaphore instruction to be skipped,

if (rsi_driver_cb->wlan_cb->expected_response != RSI_WLAN_RSP_ASYNCHRONOUS) {
#ifndef RSI_NWK_SEM_BITMAP
rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0);
#endif
}

which causes the wait/post flow of the driver to get out of whack and can produce some nasty effects. In my case a subsequent SAPI call was returning early instead of waiting and when the RX event it should have been waiting on was processed, it filled a buffer that had gone out of scope.

I fixed this one by adding an else clause:
else { rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_FTP; }
I'm not positive this is the appropriate response to use, but it seems to work.

@adam-durridge adam-durridge changed the title Bugs in rsi_ftp_file_write_content() causing stack corruption and deadlock Bug in rsi_ftp_file_write_content() causing stack corruption and deadlock Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant