Skip to content

Commit

Permalink
fix(radio): potential crash when writing .luac files (#5732)
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz authored Dec 24, 2024
1 parent c4bc672 commit 28b0cb9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions radio/src/lua/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ FRESULT dresult = FR_OK;
static int luaDumpWriter(lua_State * L, const void* p, size_t size, void* u)
{
UNUSED(L);
UINT written;
const uint8_t* b = (const uint8_t*)p;
while (size > 0) {
int len;
Expand All @@ -372,7 +373,7 @@ static int luaDumpWriter(lua_State * L, const void* p, size_t size, void* u)
b += len;
if (dpos >= DLEN) {
// Write to SD when buffer full
dresult = f_write((FIL *)u, dbuf, dpos, nullptr);
dresult = f_write((FIL *)u, dbuf, dpos, &written);
dpos = 0;
if (dresult != FR_OK)
break;
Expand Down Expand Up @@ -402,7 +403,8 @@ static void luaDumpState(lua_State * L, const char * filename, const FILINFO * f
lua_unlock(L);
if (dpos > 0) {
// Write last piece
dresult = f_write(&D, dbuf, dpos, nullptr);
UINT written;
dresult = f_write(&D, dbuf, dpos, &written);
}
if (dresult != FR_OK) {
// Save failed, close file handle and delete file.
Expand Down

0 comments on commit 28b0cb9

Please sign in to comment.