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

Add missing error check #68

Merged
merged 2 commits into from
Jul 8, 2024
Merged

Add missing error check #68

merged 2 commits into from
Jul 8, 2024

Conversation

archigup
Copy link
Member

@archigup archigup commented Jul 5, 2024

In FF_Write a loop is used to write remaining blocks, and breaks are
used to terminate on error. However, these breaks intended to break the
containing do-while. As they do not, on error from FF_BlockWrite,
control would get passed to after the loop, FF_SetCluster would clear
the error, and FF_WritePartial would be called with ulBytesLeft greater
than block size, which is invalid and causes out of bounds memory
writes.

This is fixed by checking the error after the loop and breaking again.

Should fix https://forums.freertos.org/t/freertos-fat-memory-overwrite-in-ff-writepartial/20894

In FF_Write a loop is used to write remaining blocks, and breaks are
used to terminate on error. However, these breaks intended to break the
containing do-while. As they do not, on error from FF_BlockWrite,
control would get passed to after the loop, FF_SetCluster would clear
the error, and FF_WritePartial would be called with ulBytesLeft greater
than block size, which is invalid and causes out of bounds memory
writes.

This is fixed by checking the error after the loop and breaking again.
Copy link
Contributor

@htibosch htibosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Carl for the analysis, and Archit for the quick reparation.
We should have tested with simulation I/O errors before.
I approve the change.

Copy link
Contributor

@carlk3 carlk3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great! Thanks.

Now if I return FF_ERR_IOMAN_DRIVER_FATAL_ERROR | FF_ERRFLAG from my fnWriteBlocks I get "Protocol driver not attached (42)" and no crash. If I return FF_ERR_DEVICE_DRIVER_FAILED | FF_ERRFLAG I get "I/O error (5)", which I think I like better. Either way, at least I get a chance to recover.

@archigup archigup merged commit ff1e980 into FreeRTOS:main Jul 8, 2024
5 checks passed
@archigup archigup deleted the error_break branch July 8, 2024 16:58
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

Successfully merging this pull request may close these issues.

5 participants